码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2014-05-21 14:39:37      阅读:321      评论:0      收藏:0      [点我收藏+]

标签:blog   class   c   code   tar   http   

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带有参数表单的使用方法,布布扣,bubuko.com

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

标签:blog   class   c   code   tar   http   

原文地址:http://blog.csdn.net/nohackcc/article/details/26345173

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!