iOS 앱에서 POST 메소드를 보내고 있습니다. 내 코드는 정상적으로 작동하지만 사본을 붙여 넣기 만하면됩니다.iOS 필수 헤더의 POST 요청
NSString *post = @"key1=val1&key2=val2";
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:@"http://www.nowhere.com/sendFormHere.php"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
내 질문은 : HTTP 헤더 필드에서 아무것도를 설정하는 필수인가?
예인 경우 어떤 헤더 필드가 필요합니까?
감사합니다.
감사합니다! 따라서 콘텐츠 유형도 필요하지 않습니다. 기본 콘텐츠 유형은 무엇입니까? –
@ BalázsVincze 기본 콘텐츠 형식이없는 것 같습니다. 그러나 postData가 설정된 경우 사용할 수있는 두 가지 유형이 있습니다. http://stackoverflow.com/questions/4007969/application-x-www-form-urlencoded-or-multipart-form-data – forkaj