ASFormDataRequest POST request error

im using this code to send 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: {Message: the requested resource does not support the http 'GET' method.}

what am I doing wrong?

0
source share
1 answer

You mix things here. You create an ASIFormDataRequest , but you are not actually sending it. What you submit is NSURLConnection .

It has been a long time since I used ASI, but this could 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]; 

As a tip, replace the ASI with something like AFNetworking. ASI is no longer being developed.

+2
source

All Articles