I am trying to Request for REST POST API with XML string but I am getting following error response.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<apiErrors>
<apiError>
<errorMessage>415 Unsupported Media Type - null</errorMessage>
</apiError>
</apiErrors>
I don't understand why this happening. Even I set content-type and header also.
Please take a look at my code.
String XmlString = "<Contact>"
+"<name>Sandeep</name>"
+"<title>Mr.</title>"
+"<Address>India</Address>"
+"</Contact>";
try {
StringEntity se = new StringEntity(XmlString);
HttpPost httpRequest = new HttpPost("http://abc:xyz123@000.000.000.00:8080/aaa/sample/feed/000001");
httpRequest.setHeader("Content-Type","application/soap-xml;charset=UTF-8");
httpRequest.setHeader("Accept","text/plain");
httpRequest.setEntity(se);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse httpResponse;
httpResponse = httpclient.execute(httpRequest, new BasicHttpContext());
finalres = inputStreamToString(httpResponse.getEntity().getContent())
.toString();
Please give me hint or reference.
If you use
@Consumes(MediaType.APPLICATION_XML)
in your REST service then use content type as followsCheck you application using browser REST clients such as Curl, Advanced rest clent, etc.
In your request you are specifying the communication to be soap-xml
Try to specify to use plain xml by removing the "soap" part.
Valid xml content types:
"text/xml" or "application/xml"
Soap calls are very specifically formatted xml and from the response, unless you trimmed the output to remove all of the soap xml, it appears to be a plain xml service.
Did you try without charset="utf-8"?
(I couldn't leave a comment due to my low reputation)