I am using the instructions provided in the ASI page here. I am trying to send some data to a web service and not seeing any results.
This is my sendRequest
method which gets called in viewDidLoad
-(void)sendRequest {
NSURL *url = [NSURL URLWithString:@"http://153.60.6.75:8080/BarcodePayment/transactions"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request addRequestHeader:@"Accept" value:@"application/json"];
[request addRequestHeader:@"Content-Type" value:@"application/json"];
NSString *dataContent = @"{\"id\":7,\"amount\":7.0,\"paid\":true}";
NSLog(@"dataContent: %@", dataContent);
[request appendPostData:[dataContent dataUsingEncoding:NSUTF8StringEncoding]];
[request setRequestMethod:@"POST"];
}
I check the dataContent
string and the output is
{"id":7,"amount":7.0,"paid":true}
If I use curl from Terminal, I checked and this command works.
curl -X POST -H 'Accept:application/json' -H 'Content-Type: application/json' http://153.60.6.75:8080/BarcodePayment/transactions/ --data '{"id":7,"amount":7.0,"paid":true}'
My understanding is that in using curl, I set it to json, specify the address, specify the data which is equivalent to dataContent
in my code. Nothing happens. What's wrong?
Thanks for the help!