- Kenneth Hughson
- PowerBuilder
- Tuesday, 26 April 2022 06:14 PM UTC
Does anyone have either
- any successful examples of using HTTPClient to consume a .Net Web API that requires XML to be passed to it? OR
- know why I’m receiving the error\issues below when trying to pass the XML?
I’m using PowerBuilder 2021 Professional Build 1288 to pass 7 parameters to the API, 6 are strings and 1 is XML. I have tried passing the XML to a string, XMLText and XMLDocument. Is there something I need to do to pass long XML? If the XML is submitted as string data Postman, ReadyAPI and the browser will return a 200 response with the data successfully processed.
Errors:
Bad Request - Invalid URL
HTTP Error 400. The request URL is invalid.
Or
An error has occurred.
A potentially dangerous Request.Path value was detected from the client (=\"...tResponse/<LOAD_PAYABLE>/AP/LO...\")
The Web API POST/GET method:
[HttpPost]
[Route("api/Payable/GetDocumentResponse/{txtxmldocument}/{doctype}/{docsubtype}/{docnumber}/{docpartysite}/{docusername}/{docpassword}")]
public string GetDocumentResponse(string txtxmldocument, string doctype, string docsubtype, string docnumber, string docpartysite, string docusername, string docpassword)
{
.........code
}
The PowerBuilder code that has no effect on the Web API call has been removed, The ls_parameter variable will be using values passed into the method. The username and password are basically not being used.
Any XML will fail for example “<ADRESS></ADDRESS>. Actually any string value will also fail if it contains characters such as “<,>,?,/”
The PowerBuilder code:
httpClient lo_client
Integer li_ret , li_StatusCode
String ls_json, ls_body, ls_ret, ls_parameter
UO_DATASTORE_CONTROL lds_get_parm, lds_message
lo_client = Create HttpClient
lo_client.SetRequestHeader("Content-Type", "application/json;charset=UTF-8")
ls_parameter = '{"
li_ret = lo_client.SendRequest("POST", "https://localhost:44395/api/Payable/GetDocumentResponse/", ls_json, EncodingUTF8!)
if li_ret = 1 then
li_StatusCode = lo_client.GetResponseStatusCode()
if li_StatusCode = 200 then
lo_client.GetResponseBody(ls_body)
ls_ret = lo_client.GetResponseStatusText()
else
ls_ret = lo_client.GetResponseStatusText()
end if
end if
Return ls_ret
Destroy ( lo_client )
Thanks, Ken H
Find Questions by Tag
Helpful?
If a reply or comment is helpful for you, please don’t hesitate to click the Helpful button. This action is further confirmation of their invaluable contribution to the Appeon Community.