即时通讯使用此代码将数据发布到我的服务器
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];
在方法中
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
NSLog(@"%@",error);
}
即时通讯:
{消息:请求的资源不支持http方法'GET'。}
我在做什么错?
最佳答案
您在这里混在一起。您构建了一个ASIFormDataRequest
,但实际上并未发送它。您发送的是一个NSURLConnection
。
自从我使用ASI已经很长时间了,但这可能会有所帮助:
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];
提醒一下,用AFNetworking之类的东西代替ASI。不再开发ASI。
关于ios - ASIFormDataRequest POST请求问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22115587/