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

問題は、アクションが「/ foo」であることをPOSTに伝えることだと思いますが、それはわかりません。これを行うのはこれが初めてで、Google で何の助けも見つかりませんでした。

4

1 に答える 1

0

あなたは自分の質問に答えました - URL には へのパスが含まれていませんfoo.jsp。に変更http://localhost:8888/してみてくださいhttp://localhost:8888/path/to/foo.jsp

于 2010-10-27T21:05:49.030 に答える