ios中怎么进行delete请求
发布网友
发布时间:2022-04-23 21:50
我来回答
共1个回答
热心网友
时间:2023-10-10 23:21
1,普通的DELETE只需加上下述一句code:
[objc] view plain copy
[request setRequestMethod:@"DELETE"];
2,附带有参数表单的情况(一次删除请求):
[objc] view plain copy
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 plain copy
[request setPostValue:username forKey:@"userpair_name"];
只添加
[objc] view plain copy
[request setRequestMethod:@"DELETE"];
这行代码并不能正确实现DELETE,
需要添加
[objc] view plain copy
[request buildPostBody];
另外注意 setRequestMethod:@"DELETE"这行要在buildPostBody之后。