6

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

Jean-Étienne
  • 145
  • 2
  • 9
creator_11
  • 701
  • 1
  • 7
  • 12

2 Answers2

7

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.

JosephH
  • 37,173
  • 19
  • 130
  • 154
  • thanks for your hint you also sent to me in this google group. As mentioned there the suggested solution with the additional "buildPostBody" statement worked fine and the DELETE request now succeeds. thanks. – creator_11 Jun 28 '11 at 22:40
2

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.

RyanR
  • 7,728
  • 1
  • 25
  • 39
  • as mentioned above a solution with an additional "buildPostBody" statement worked fine. I agree that from a pure REST point of view you are right and the resource to be deleted should be specified within the URI. But as far as I know does the http protocol spec. NOT forbid any post data together with a DELETE request. since our server appl. does not rely on "pure" REST it just requires some resource specifiers as post data which is now possible to send them. Nevertheless I will discuss this point with the people responsible for the server appl. just to improve the design. Thank you. C. – creator_11 Jun 28 '11 at 22:56