0

我正在尝试从带有一些参数的 iPhone 应用程序发送 HttpRequest。表格是这样的:

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>

因此,在用户按下按钮时的 iPhone 方法中是:

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];

我想问题是告诉 POST 动作是“/foo”,但不确定是不是这样。这是我第一次这样做,并没有在 Google 上找到任何帮助。

4

1 回答 1

0

您回答了自己的问题 - URL 不包含foo.jsp. 尝试更改http://localhost:8888/http://localhost:8888/path/to/foo.jsp.

于 2010-10-27T21:05:49.030 回答