Reputation: 347
I am trying to POST a sample data to a server using REST api from ASIHTTPRequest in iphone. When i try from REST client from mozilla browser , I get success code 200 . But when i try from iphone i get 415 code and the error message reads as "Cannot consume content type" and "The supplied request data is not in a format acceptable for processing by this resource."
Here is my code,
ASIFormDataRequest *request2 = [ASIFormDataRequest requestWithURL:myurl];
[request2 setUsername:User_Name ];
[request2 setPassword:Pass_Word];
[request2 addRequestHeader:@"Content-Type" value:@"application/xml;version=1"];
[request2 setPostBody:[NSMutableData dataWithData:mydata dataUsingEncoding:NSUTF8StringEncoding]]];
[request2 setRequestMethod:@"POST"];
[request2 setDelegate:self];
[request2 startAsynchronous];
Please help me to solve this issue.
Thanks and Regards, Vinod.
Upvotes: 0
Views: 822
Reputation: 5266
Hard to tell from the lack of details, but I'd say the mydata -> encoded utf8 isn't the format the server is expecting (is it supposed to be XML formatted?)
Add some sample from the REST client and iphone version for the posted data.
EDIT: more info
add the NSLog line as I have below, and see if the output matches the XML format in your comment.
ASIFormDataRequest *request2 = [ASIFormDataRequest requestWithURL:myurl];
[request2 setUsername:User_Name ];
[request2 setPassword:Pass_Word];
[request2 addRequestHeader:@"Content-Type" value:@"application/xml;version=1"];
[request2 setPostBody:[NSMutableData dataWithData:mydata dataUsingEncoding:NSUTF8StringEncoding]]];
NSLog(@"%@", [NSMutableData dataWithData:mydata dataUsingEncoding:NSUTF8StringEncoding]);
[request2 setRequestMethod:@"POST"];
[request2 setDelegate:self];
[request2 startAsynchronous];
Upvotes: 0
Reputation: 9157
I'm guessing there's something wrong with the content-type header you're setting. I've had a possibly unrelated issue where a content-type of application/xml wasn't accepted and a content-type of text/xml was being processed by the web server.
One way to debug this I think is to use something like https://addons.mozilla.org/en-US/firefox/addon/httpfox/ to look at the raw HTTP request that goes out when you access the website through your browser and set the same headers in ASI.
Upvotes: 2