views:

381

answers:

1

Hello All,

There are a lot of questions on Stackoverflow about curl but I could not figure out what is that I am doing what I am not supposed to. I am trying to call a RESTful service that I had written using Jersey API and am trying to POST an xml string to it and I get HTTP 415 error which is supposed to be a Media Type error.

Here in my shell script call to 1st service:

abc=curl http://gf...:8080/InChItoD/inchi/3dstructure?InChIstring=$inchi

echo $abc (this works fine the output that it returns is given below.)

Posting this xml string to second service

def= curl -d $abc -H "Content-Type:text/xml" http://gf...:8080/XML2G/xml3d/gssinput

I get the following error:

... ... HTTP Status 415 Status report message description.The server refused this request because the request entity is in a format not supported by the requested resource for the requested method ().Apache Tomcat/6.0.26

This is a sample of xml string I am trying to POST

<?xml version="1.0"?><molecule xmlns="http://www.xml-cml.org/schema"&gt; <atomArray> <atom id="a1" elementType="N" formalCharge="1" x3="0.997963" y3="-0.002882" z3="-0.004222"/> <atom id="a2" elementType="H" x3="2.024650" y3="-0.002674" z3="0.004172"/> <atom id="a3" elementType="H" x3="0.655444" y3="0.964985" z3="0.004172"/> <atom id="a4" elementType="H" x3="0.649003" y3="-0.496650" z3="0.825505"/> <atom id="a5" elementType="H" x3="0.662767" y3="-0.477173" z3="-0.850949"/> </atomArray> <bondArray> <bond atomRefs2="a1 a2" order="1"/> <bond atomRefs2="a1 a3" order="1"/> <bond atomRefs2="a1 a4" order="1"/> <bond atomRefs2="a1 a5" order="1"/> </bondArray></molecule>

Thanks in advance

+2  A: 

first you can try quoting your $abc string. eg curl -d "$abc". If that doesn't help, try escaping those metacharacters, like double quotes and forward slashes. eg

abc=$(echo "$abc" | sed 's|\(["/]\)|\\&|g' )
ghostdog74
Escaping those metacharacters did not resolve it. By putting $abc in double quotes I dont see the HTTP 415 error anymore but I dont see that it is getting posted to my service.
Sashikiran Challa
Thanks! There was a mistake in my service and not in the curl statement. I mean I had to correct that error in my service and use double quotes in the curl. Thanks again.
Sashikiran Challa