ASIHttpRequest DELETE method with body parameters

I am using ASIHttpRequest (version 1.8-95) for Iphone and wanted to create a synchronous DELETE request along with some body data. I went like this:

ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:nsUrl]; [request appendPostData:[@"some body params" dataUsingEncoding:NSUTF8StringEncoding]]; [request setRequestMethod:@"DELETE"]; [request startSynchronous]; 

Although I have been confirmed on the client side through

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

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

If I just lower

 [request appendPostData: ..] 

on the server side received the correct DELETE)

So what happened to my request? Thanks for any solutions.

respectfully

creator_11

+6
source share
2 answers

A search for the asihttprequest group ( http://groups.google.com/group/asihttprequest/search?group=asihttprequest&q=delete&qt_g=Search+this+group ) brings up some relevant messages, including the recommended method:

call buildPostBody according to your request after you have filled the body, but before setting the request method.

+7
source

HTTP verbs and customs cannot be confused or matched. Well, they can, but you will need to change the server to support your custom use. DELETE must use the URI of the resource to be deleted, and thats it. No POST options, no binding.

If you really want to send additional data along with the deletion, you can set it in the request headers ( addRequestHeader:value: , and on the server side display this information, but avoid this if you can. The reason is that DELETE must delete one β€œthing” referenced by its URI. If the business logic of the server application says that the deletion should affect some other objects (for example, cascading deletion), the client application should not be aware of this.

Can you explain that you are trying to execute POST while DELETE is running, maybe I can offer an alternative solution.

+2
source

Source: https://habr.com/ru/post/891502/


All Articles