|
FOROS PROFESIONALES WINDEV, WEBDEV y WINDEV Mobile |
| | | | | |
| Iniciado por kim.oregan, 05,dic. 2019 11:32 - 6 respuestas |
| |
| | | |
|
| |
| Publicado el 05,diciembre 2019 - 11:32 |
Hi all,
I'm trying to figure out how to create an API-request in Windev.
The request looks like this: <?xml version='1.0' encoding='ISO-8859-1'?> <marathon> <password>abc123</password> <type>api_operation</type> <company_id>ABC</company_id> <employee_id>ABC123</employee_id> <date>2019-12-04</date> <repeat_until></repeat_until> <client_id>ABC</client_id> <project_no>123</project_no> <feecode_id>123</feecode_id> <hours>4,5</hours> <full_time_percentage></full_time_percentage> <comment>ABC-1234 Working</comment> </marathon>
Which is posted to: "https://adress_of_webservice"
How would I do this in Windev?
Thankful for any help
Regards /Kim |
| |
| |
| | | |
|
| | |
| |
| Publicado el 05,diciembre 2019 - 13:01 |
Try this:
sXml is string = [ <?xml version='1.0' encoding='ISO-8859-1'?> <marathon> <password>abc123</password> <type>api_operation</type> <company_id>ABC</company_id> <employee_id>ABC123</employee_id> <date>2019-12-04</date> <repeat_until></repeat_until> <client_id>ABC</client_id> <project_no>123</project_no> <feecode_id>123</feecode_id> <hours>4,5</hours> <full_time_percentage></full_time_percentage> <comment>ABC-1234 Working</comment> </marathon> ]
Req is httpRequest cReq.URL = https: cReq..ContentType = "application/xml" cReq..Method = httpPost cReq..Content = sXml
cResp is httpResponse = HTTPSend(cReq)
SWTICH cResp..StatusCode CASE 200 OTHER CASE END |
| |
| |
| | | |
|
| | |
| |
| Publicado el 05,diciembre 2019 - 15:13 |
Hi and thanks for the answer Jeroen. Your example worked when I put in the XML-request in the sXml brackets. The "problem" is that I will be reading rows from a database and sending them with httpPost. So some of the values has to be variables. How do I achieve that?
Functioning: sXml is string = [ <?xml version='1.0' encoding='ISO-8859-1'?> <marathon> <password>abc123</password> <type>api_operation</type> <company_id>ABC</company_id> <employee_id>ABC123</employee_id> <date>2019-12-04</date> <repeat_until></repeat_until> <client_id>ABC</client_id> <project_no>123</project_no> <feecode_id>123</feecode_id> <hours>4,5</hours> <full_time_percentage></full_time_percentage> <comment>ABC-1234 Working</comment> </marathon> ]
cReq is restRequest cReq.URL = "https://webservice_server" cReq..ContentType = "application/xml" //or "text/xml" cReq..Method = httpPost cReq..Content = sXml //cReq.Header["x-auth-token"] = "???" //optional: sometimes needed for authentication
cResp is restResponse = HTTPSend(cReq)
Regards /Kim |
| |
| |
| | | |
|
| | |
| |
| Publicado el 06,diciembre 2019 - 14:20 |
Try this:
xmlDoc is xmlDocument xmlDoc..Encoding = XMLEncodingUTF8
xmlDoc.marathon.password = "abc123" xmlDoc.marathon.type = "api_operation" xmlDoc.marathon.company_id = "ABC" xmlDoc.marathon.employee_id = "ABC123" xmlDoc.marathon.date="2019-12-04" xmlDoc.marathon.repeat_until = "" xmlDoc.marathon.client_id="ABC" xmlDoc.marathon.project_no=123 xmlDoc.marathon.feecode_id=123 xmlDoc.marathon.hours=4.5 xmlDoc.marathon.full_time_percentage="" xmlDoc.marathon.comment="ABC-1234 Working"
cReq is httpRequest cReq.URL = "https://adress_of_webservice" cReq..ContentType = "application/xml" cReq..Method = httpPost cReq..Content = XMLBuildString(xmlDoc,XMLDocumentDefault)
cResp is httpResponse = HTTPSend(cReq)
SWITCH cResp..StatusCode CASE 200 OTHER CASE END |
| |
| |
| | | |
|
| | |
| |
| Publicado el 06,diciembre 2019 - 16:46 |
Hi and thanks for the answer, again, Jeroen!
I will try this.
/Kim |
| |
| |
| | | |
|
| | |
| |
| Publicado el 09,diciembre 2019 - 16:36 |
Hi Jeroen, I get this when running the script:

"Failure retrieving the XML. unknown encoding 2 .content"
Tried the "text/xml" to no prevail.
The Content seems to be empty.
What's missing?
Regards /Kim |
| |
| |
| | | |
|
| | |
| |
| Publicado el 10,diciembre 2019 - 19:01 |
Hi, I've managed to implement the XML-part into my application. So now it sends and stores the info in the database. I do though have a "small" problem. I use time in my application which is formatted hh:mm. The recieving system use either hh,mm or hh.mm and, e.g 1:30 is displayed 1,5 or 1.5 on the recieving system. How do I convert e.g 1:30 to 1,5?
Regards /Kim |
| |
| |
| | | |
|
| | | | |
| | |
| | |
| |
|
|
|