2

I have to send some data using POST to a backend that checks the content type and forces "text/xml". I'm using this code:

final ClientResource resource = new ClientResource(url);
String data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> ..."
StringRepresentation stringRep = new StringRepresentation(data);
stringRep.setMediaType(MediaType.TEXT_XML);
resource.post(stringRep);

It seems that Restlet uses "text/plain" as content type. Is it possible to force the content type? I'm using Restlet 2.0 on Android 2.2.

Thanks in advance

Steven

Steven Mohr
  • 1,167
  • 6
  • 19

1 Answers1

1

I made some tests using the code your gave with Restlet 2.0.3 and changing the content type on the representation actually changes the corresponding header in HTTP request.

You say "It seems that Restlet uses "text/plain" as content type". How do you check that? On my side, I used the Tcp Mon tool from Apache as a proxy to see the request content (http://ws.apache.org/commons/tcpmon/download.cgi). Otherwise which 2.0 version do you use? This will allow having the same environment as you...

Thanks, Thierry

Thierry Templier
  • 198,364
  • 44
  • 396
  • 360
  • Thank you for giving me the hint on that tool. I had no idea how to verify it on my own before so I will check the header myself. I had to rely on my project partner who told me that this was the problem. I'm using Restlet 2.0.6 for Android with the ext.net extension. – Steven Mohr Apr 21 '11 at 08:08
  • I've tested the transmission using TcpMon now and it seems that everything works fine! Seems to be a server problem. Thank you for testing my code and giving me the link to that tool! – Steven Mohr Apr 21 '11 at 08:30
  • http://requestb.in/ is also super handy when testing API stuff. Just hit it with anything you want and you can check what it received (headers, http method, data content, etc.) Obviously it won't send _back_ any response you'd be expecting from the server, but it's useful to make sure your client's requests are valid. – JMTyler Dec 03 '12 at 01:12