开发者

ASIHttpRequest DELETE method with body parameters

I use ASIHttpRequest (v. 1.8-95) for Iphone and wanted to create a synchronous DELETE request together with some body data. I went this way:

ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:nsUrl];
[request appendPostData:[@"some body params" dataUsingEncoding:NSUTF8StringEncoding]];
[request setRequestMethod:@"DELETE"];开发者_高级运维
[request startSynchronous];

Although I was confirmed on the client side via

NSLog(@"request: method:%@", request.requestMethod);

that the method was correctly set to "DELETE" on the server side a "POST" request was received !

If I just omit

[request appendPostData: ..]

a correct DELETE is received on the server side)

So what's wrong with my request ? Thanks for any solutions.

Regards

creator_11


Searching the asihttprequest group ( http://groups.google.com/group/asihttprequest/search?group=asihttprequest&q=delete&qt_g=Search+this+group ) turns up some relevant posts including a suggested workaround:

call buildPostBody on your request after you've populated the body, but before you set the request method.


HTTP verbs and usages can't just be mixed and matched. OK, they can, but you'd have to change the server to support your non-standard usage. DELETE should use the URI of the resource to be deleted, and thats it. No POST params, no attachment.

If really you want to send a little extra data along with the delete, you can set it in the headers of the request (addRequestHeader:value:), and server side pull that info out, but avoid that if you can. The reason is, the DELETE should be deleting one 'thing' referred to by it's URI. If the business logic of the server application says that delete should affect some other objects (eg cascading delete), the client application shouldn't know about that.

Can you explain what you're trying to POST while performing a DELETE, maybe I can offer an alternative solution.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜