次のコードがあります。
NSString *post = @"i hope this gets there";
NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:NO];
NSString *postLength = [NSString stringWithFormat:@"%d", [post length]];
NSURL *url = [NSURL URLWithString:@"http://www.oneoftwosites.com"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:postData];
[NSURLConnection connectionWithRequest:request delegate:nil];
//potential response
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
//convert response so that it can be LOG'd
NSString *returnString = [[NSString alloc] initWithData:response encoding:NSASCIIStringEncoding];
NSLog(@"RETURN: %@", returnString);
http://www.htmlcodetutorial.com/cgi-bin/mycgi.plとhttp://instagraph.me/postの 2 つの異なる Web サイトで、これらの URL を に置き換えてテストしましたhttp://www.oneoftwosites.com
。何らかの理由で、最初の Web サイト (perl で記述) でのみ機能し、2 番目の Web サイト (.php で記述) では機能しません。
なぜこれが考えられるのか、誰にもアイデアがありますか? たまにしか機能しないのはばかげているようですが、2番目のWebサイトで機能しない理由がまったくわかりません(コードは見ていませんが、サンプル出力はいくつか見ました)。
編集:追加しました
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
いくつかの異なるタイプを試しましたが、まだ運がありません