ios ASIHttpRequest库进行DELETE操作时delete带有参数表单的使用方法

1,普通的DELETE只需加上下述一句code:

[request setRequestMethod:@"DELETE"];
2,附带有参数表单的情况(一次删除请求):

    ASIFormDataRequest *request;
    NSURL *baseURL = [NSURL URLWithString:@"http://www.baidu.com/xx/"];
    request = [ASIFormDataRequest  requestWithURL:baseURL];
    

    //header
    [request addRequestHeader:@"Authorization" value:headerforAuthen];
    
    //form
    [request setPostValue:username forKey:@"userpair_name"];
    
    /// Call this before setting request method
    [request buildPostBody];
    
    //构造请求
    [request setRequestMethod:@"DELETE"];
    
    //设置代理
    [request setDelegate:self];
    
    //设置超时
    [request setTimeOutSeconds:10];
    
    //url请求失败处理
    [request setDidFailSelector:@selector(urlRequestFailed_DeleteUserPair:)];
    
    //url请求成功处理
    [request setDidFinishSelector:@selector(urlRequestSuccessed_DeleteUserPair:)];
    
    //异步传输
    [request startAsynchronous];
    return YES;
    

说明:

现有要提交的数据:

[request setPostValue:username forKey:@"userpair_name"];

只添加

[request setRequestMethod:@"DELETE"];
这行代码并不能正确实现DELETE,

需要添加

    [request buildPostBody];
另外注意 setRequestMethod:@"DELETE"这行要在buildPostBody之后。

参考:stackoverflow:http://stackoverflow.com/questions/15518394/asiformdatarequest-with-setpostvalue-and-method-delete

ios ASIHttpRequest库进行DELETE操作时delete带有参数表单的使用方法,,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。