posting xml data from java to rails (restful service)
I'm trying to post an xml document from java to a rails application. I have a hard time writing the http request Here's my java code:
Socket sock = new Socket(addr, port);
String path = "http://127.0.0.1:3000/mycontrollers.xml";
BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream(), "UTF-8"));
wr.write("POST +path+ " HTTP/1.0\r\n");
wr.write("Host: http://127.0.0.1:3000\r\n");
wr.write("Content-Length: " + xmldata.length() + "\r\n");
wr.write("Content-Type: text/xml; charset=\"utf-8\"\r\n");
wr.write("\r\n");
//Send data
wr.writ开发者_StackOverflow中文版e(xmldata);
wr.flush();
In return I have : Not Found: /mycontrollers.xml
Any ideas?
Thanks a lot
Why not using already implemented solutions from caucho: hessian or burlap library? This is available for ruby and java.
And did you try to post the xml with more simple tools (e.g. the firefox plugin)?
I think you will need to implement the rails side for you job too. (I know that one could easily retrieve xml from rails but not the otherway around I think)
From the error you're seeing it sounds like you don't have the routing setup to handle /mycontrollers.xml
in your Rails application. Are you using the resource helpers or have you defined a custom route?
If you've defined your own route you'll need to add .:format
to the route so that Rails can pick up the content type from the url.
Another alternative would be to send the Accept
header in your POST
and send it to /mycontrollers
rather than /mycontrollers.xml
.
精彩评论