So at first glance everything looks the same as the curl request, but when sent with httpClient it’s not working for some reason.
Am I missing something?
Is there some hidden syntax that I need to use for the body of the request, e.g. in CMD a JSON payload is wrapped in escaped double quotes (\") so it’s parsed correctly.
Or maybe there is a way to see the complete POST packet before it’s sent out the “door”, without running it through a proxy and using Wireshark?
I’m not sure but I could imagine that the API is missing some request header information that is set automatically when using curl, like User-Agent or Referer.
As concrete example why I’m thinking about that, please see the following post:
To see all header information, you could use the rawHeader element of type httpRawHeader_t, which is an element of the request and response header structure.
Some more infos about header and raw header you can find in this conversation:
But to see the whole http conversation, I would propose to use wireshark.
You can view the complete communication using API testing tools (I prefer Postman), including request and response bodies and headers, and adapt your request accordingly.
From my experience, the authentication data is typically part of the request header (it’s better to use the rawHeader instead of the user field), and it fully depends on the type of authorization (e.g., Basic or Digest).
okay, thanks for the update.
What service is behind this api, is there any documentation available online?
In the swagger page, the accept header of the request is set to text/plain, have you tried to set this also, or maybe for test, accept: / could be also fine?
About sniffing your request: for testing, you could use the PLC simulation on your Automation Studio notebook, then you should be able to see request and response in your wireshark installation?
The problem was that I was calling the httpClientInst.requestDataLen := SIZEOF(x), when it should be brsstrlen(ADR(x))
The content length was 256 instead of the actual USED content length(61 in my case), therefore asHttp function would put many “********” after the body to fill it to the content length of 256, which the API of course did not accept as a valid body.
Below this is the final code that works for me if any time travelers in the future need it: