POST Json/xml format in easyhttp
yuvalluba
I have some problem and hoping you could help me. I'm trying to write a procedure which communicate with a server (via the internet). As for the GET functions, everything is working great with the easyhttp function. On the other hand, I have problems with the POST function. The server can only receive Json or xml text format. I tried sending it such text in a string but I'm getting this kind of massage- "Unsupported Content-Type. The supported types are application/json,text/json,application/xml,text/xml". The reason is probably that the Content-Type in the HTTP Request "inside" the easyhttp is "application/x-www-form-urlencoded" or whatever and not the types I need.
Does anyone knows whether it possible to change the Content-Type in the HTTP Request? How can it be done?
I will be extremely grateful if you could help me pass this challenge or suggest any other method to POST Json/xml text format with IgorPro.
Thanks in advance,
YL
If you have the XOP toolkit and are comfortable with C code, it probably wouldn't take much effort to modify the XOP to support this feature, since the source code for the XOP is available in Subversion (svn://svn.igorexchange.com/packages/easyHttp/). If you search for curl_formadd in easyHttp.cpp (at http://svn.igorexchange.com/viewvc/packages/easyHttp/trunk/src/easyHttp…), the code is adding the form keyword/value pairs. I think you could add a new call to curl_formadd before that where you set CURLFORMCONTENTTYPE.
The best place to suggest such a feature for the easyHttp XOP would be http://www.igorexchange.com/node/add/project_issue/easyHttp/feature, but I would guess that Andy would see this post eventually as well.
December 2, 2014 at 08:13 am - Permalink
No, i don't have the XOP and don't have much experience with it nor C#. Never the less, if i would not have any other choice, i will gain some in order to complete this task.
I'll suggest this small feature to Andy and maybe he will be kind to make it and save me a LOT OF TIME…
December 2, 2014 at 11:00 am - Permalink
Is this server readily available to the outside world?
One thing that helps in debugging is installing something like "Live Http headers" into your browser. If you carry out the operation from your browser you'll be able to see the headers that the webpage sends. Verify what headers are being sent and what the request looks like.
Then try and repeat the request using curl from a terminal window (in OSX, otherwise you'll have to install cygwin on Windows probably). Once you've got that working I may be able to modify the XOP to do what you want, but I'm quite busy.
December 2, 2014 at 04:18 pm - Permalink
I'll try those steps and let you know.
Thanks,
YL
December 2, 2014 at 08:29 pm - Permalink
I try both with /POST and /FORM, neither worked.
This server isn't really available….
I couldn't really commute with the server via the browser since it's an API with username+password
BUT, I did succeed POSTing to it from the terminal window. I wrote this command:
curl -X POST -H "Content-Type:application/json" -d '{"name":"content"}' https://UserName:PassWord@bla_bla/bla/bla/bla
where {"name":content"} is the post-string.
So, I believe the only adjustment needed is to replace "text/html" in the header to "application/json"
What do you think?
Thanks in advance.
YL
December 3, 2014 at 12:23 pm - Permalink
It's OK, I found the "magic" function: "ExecuteScriptText" and everything is working…
Thanks again,
YL
December 5, 2014 at 06:55 am - Permalink