开发者

Setting up a Restful POST request using xml

I'm w开发者_StackOverflow社区orking on setting up a RESTful request for the application I'm working on and I wanted to use xml as the request in the uri instead of allowing the client to supply the parameters in the URI itself.

I'm looking to have the URI like so: someurl/service/request

instead of: someurl/service/request?id={id}&name={name}

I have been searching the web to see what the convention should be when creating the POST request. Can anyone kind of help point me in the right direction on how I should set up this POST request allowing the client to use xml?

Not sure if it is relevant but I'm setting up the server side code in JAVA using the SPRING 3.0 framework. Please let me know if I need to supply more details.

Thanks for your help!!


You can put parameters into the body of the request. They are the same format as appending them to the URL. Eg:

POST /path/script.cgi HTTP/1.0
User-Agent: HTTPTool/1.0
Content-Type: application/x-www-form-urlencoded
Content-Length: 32

home=Cosby&favorite+flavor=flies

You can do that in prototype pretty easily with:

new Ajax.Request('someurl/service', {
method: 'post',
postBody: 'home=Cosby&favorite+flavor=flies',
encoding: 'UTF-8'});

To add your xml file, just append it to your postBody with some sort of delimiter so your cgi knows where parameters end and where xml begins.

I think that's what you were looking for, hope it helps.


You can pass whatever you want in your POST body. So if you want to use XML, you can use XML. Example:

POST /car
Content-Type: text/xml
<car>
   <date>10-10-2007<date>
   <type>Corvette</type>
</car>

HTTP/1.1 201 CREATED

I think all the REST API frameworks let you easily specify XML in the client request and server response. See Restlet's quick start for an example.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜