0

文字列をサーバーに投稿しようとしています。以下にこれらのコードがあり、動作することがわかっていますが、少なくとも 1 つの EMPTY エントリをデータベースに追加した後でのみです (基本的には "" のようにデータベースに表示されます)。NSURLRequest がこのような奇妙な動作をする理由がわかりません。誰でも理由を教えてもらえますか?

NSMutableString *postString = [NSMutableString stringWithString:@"http://website.com/post.php"];
[postString appendString:[NSString stringWithFormat:@"?loc=%@",locationBox.text]];

NSMutableURLRequest* request = [[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:postString] cachePolicy:NSURLCacheStorageNotAllowed timeoutInterval:3];    
[request setHTTPMethod:@"POST"];

postConnection = [[NSURLConnection alloc]initWithRequest:request delegate:self startImmediately:YES];
4

1 に答える 1

1

あなたがやろうとしているようなことをするためにコードを実装する必要があり、次の方法で状況に成功しました。これがコードです(あなたのURLを使用するように変更されています)、常に機能します。基本的にコードとの違いは、ContentType と HTTPHeader の明示的なセットです。

NSMutableString *postString = [NSMutableString stringWithString:@"http://website.com/post.php"];
[postString appendString:[NSString stringWithFormat:@"?loc=%@",locationBox.text]];
NSURL *url = [[[NSURL alloc] initWithString:postString] autorelease];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];

問題を解決できることを願っています。

于 2012-10-20T11:49:52.447 に答える