Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

[SOLVED] Url / Post method... Help !

itralalaitralala Posts: 7New Users
edited September 2012 in iPhone SDK Development
Hello,

I need to call API on a Apache Tomcat/6.0.33 server.

According the documentation, the post must respect the
following usage :

{
"ID":"string [<20]",
"name":"string [<30]",
"email":"string [<20]",
"country":"string [5] xx_YY"
}

So, I wrote the following code to test :

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http:", kURL_V2]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

NSString *post = @"{";
post = [post stringByAppendingFormat:@"\"ID\":\"%@\",",@"123456"];
post = [post stringByAppendingFormat:@"\"name\":\"%@\",",@"john"];
post = [post stringByAppendingFormat:@"\"email\":\"%@\",",@"john@doe.com"];
post = [post stringByAppendingFormat:@"\"country\":\"%@\"",@"us_US"];
post = [post stringByAppendingFormat:@"}"];


[request setHTTPMethod:@"POST"];
[request setHTTPBody:[post dataUsingEncoding:NSUTF8StringEncoding]];

NSURLResponse *answer = nil;
NSError *error = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&answer error:&error];

NSString *message = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"%@", message);


At the end, I still obtain a HTTP Error #415 / unsupported format

I've also tried to write the post like this :

NSString *post = @"";
post = [post stringByAppendingFormat:@"ID=%@",@"123456"];
post = [post stringByAppendingFormat:@"&name=%@",@"john"];
post = [post stringByAppendingFormat:@"&email=%@",@"john@doe.com"];
post = [post stringByAppendingFormat:@"&country=%@",@"us_US"];

--> this kind of call is working on $_POST variables into my .php script...


Any idea to help me ???

Thank you,
Post edited by itralala on
Sign In or Register to comment.