iphone sdkの文字列(つまり、単語)をウェブサーバーのURLに投稿するにはどうすればよいですか?iphone sdkのウェブサーバーのURLに文字列を投稿するには?
いくつかのサンプルコードまたはチュートリアルは高く評価されます。
ありがとうございます。
NSMutableString *httpBodyString;
NSURL *url;
NSMutableString *urlString;
httpBodyString=[[NSMutableString alloc] initWithString:@"Name=The Big Bopper&Subject=Hello Baby&MsgBody=...You knooow what I like...Chantilly lace..."];
urlString=[[NSMutableString alloc] initWithString:@"http://www.somedomain.com/contactform.php"];
url=[[NSURL alloc] initWithString:urlString];
[urlString release];
NSMutableURLRequest *urlRequest=[NSMutableURLRequest requestWithURL:url];
[url release];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setHTTPBody:[httpBodyString dataUsingEncoding:NSISOLatin1StringEncoding]];
[httpBodyString release];
NSURLConnection *connectionResponse = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];
if (!connectionResponse)
{
NSLog(@"Failed to submit request");
}
else
{
NSLog(@"--------- Request submitted ---------");
NSLog(@"connection: %@ method: %@, encoded body: %@, body: %a", connectionResponse, [urlRequest HTTPMethod], [urlRequest HTTPBody], httpBodyString);
NSLog(@"New connection retain count: %d", [connectionResponse retainCount]);
responseData=[[NSMutableData data] retain];
NSLog(@"response", responseData);
}
出典::私はそれをテストhaventはが、これは、あなたを助けるかもしれ
デバイスがインターネットに接続されているかどうかを確認する方法は? – Piscean