本文介绍了ASIFormDataRequest POST请求问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用此代码将数据发布到我的服务器
im using this code to post data to my server
NSURL *mainurl = [NSURL URLWithString:@"http://xxxxxxxxxx/api/PhonePaymentApi/Transaction/"];
NSString * postdata = [[NSString alloc]initWithFormat:@"UniqueId=%@&jsonProduct=%@&BranchId=%@&OrderToTime=%@",GETUnicidentifire,JsonOrderDetail,BranchId,OrderToTime];
ASIFormDataRequest *requestt = [ASIFormDataRequest requestWithURL:mainurl];
[requestt setRequestMethod:@"POST"];
[requestt addRequestHeader:@"application/x-www-form-urlencoded" value:@"Content-Type"];
[requestt appendPostData:[postdata dataUsingEncoding:NSUTF8StringEncoding]];
NSString * theurl = [NSString stringWithFormat:@"%@",mainurl];
NSURLRequest *thereqest = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:theurl]];
[NSURLConnection connectionWithRequest:thereqest delegate:self];
方法中的
in the method
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
NSLog(@"%@",error);
}
im geting:
{消息:请求的资源不支持http方法'GET'。}
im geting:{Message:The requested resource does not support http method 'GET'.}
我做错了什么?
推荐答案
ASIFormDataRequest ,但实际上并没有发送它。你发送的是一个 NSURLConnection
。
You are mixing things up here. You build an ASIFormDataRequest
, but you don't actually send it. What you do send is an NSURLConnection
.
自从我使用ASI已经有很长一段时间了,但是这个可能有帮助:
It's been a long time since I've used ASI, but this might help:
NSURL *mainurl = [NSURL URLWithString:@"http://xxxxxxxxxx/api/PhonePaymentApi/Transaction/"];
ASIFormDataRequest *requestt = [ASIFormDataRequest requestWithURL:mainurl];
[requestt addPostValue:GETUnicidentifire forKey:@"UniqueId";
[requestt addPostValue:JsonOrderDetail forKey:@"jsonProduct";
[requestt addPostValue:BranchId forKey:@"BranchId";
[requestt addPostValue:OrderToTime forKey:@"OrderToTime";
[requestt setCompletionBlock:^{
// Process the response
}];
[requestt setFailedBlock:^{
NSError *error = [requestt error];
NSLog(@"%@",error);
}];
[requestt startAsynchronous];
作为建议,请用某些东西替换ASI像AFNetworking。 ASI不再开发。
As a word of advice, replace ASI with something like AFNetworking. ASI is no longer being developed.
这篇关于ASIFormDataRequest POST请求问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!