views:

23

answers:

1

Hello, I'm trying to send an HttpRequest from an iPhone app with some parameters. The form is like this:

foo.jsp

<form action="/foo" method="post">
<div>
    <input type="hidden" name="id" value="1" />
    <input type="hidden" name="vendidas" value="25" />
</div>
<div><input type="submit" value="Send!" /></div>
</form>

So in the iPhone method when user pushes a botton is:

NSString *myRequestString = @"id=3&vendidas=10";
NSData *myRequestData = [NSData dataWithBytes: [myRequestString UTF8String] length: [myRequestString length]];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:@"http://localhost:8888/"]];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
[request setHTTPMethod: @"POST"];
[request setHTTPBody: myRequestData];

NSError *error;
NSURLResponse *response;
NSData* result = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

I guess the problem is to tell the POST that the action is "/foo", but not sure is that. This is my first time doing this and haven't found any help with Google.

A: 

You answered your own question - the URL does not contain path to foo.jsp. Try to change http://localhost:8888/ to http://localhost:8888/path/to/foo.jsp.

Michal