我正在使用此代码将数据发布到我的服务器
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);
}
imting: {消息:请求的资源不支持http方法'GET'。}
我做错了什么?
答案 0 :(得分:2)
你在这里混合了什么。您构建了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已不再开发。