Blog / 阅读

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

by admin on 2014-05-20 10:29:47 in ,



1,普通的DELETE只需加上下述一句code:
[objc] view plaincopy
[request setRequestMethod:@"DELETE"];  
2,附带有参数表单的情况(一次删除请求):
[objc] view plaincopy
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;  


说明:
现有要提交的数据:
[objc] view plaincopy
[request setPostValue:username forKey:@"userpair_name"];  
只添加
[objc] view plaincopy
[request setRequestMethod:@"DELETE"];  
这行代码并不能正确实现DELETE,
需要添加
[objc] view plaincopy
[request buildPostBody];  
另外注意 setRequestMethod:@"DELETE"这行要在buildPostBody之后。
参考:stackoverflow:http://stackoverflow.com/questions/15518394/asiformdatarequest-with-setpostvalue-and-method-delete



写评论

相关文章

上一篇:Android 多分辨率机器适配

下一篇:深入浅出理解iOS常用的正则表达式—基础篇[Foundation]

评论

写评论

* 必填.

分享

栏目

赞助商


热门文章

Tag 云