2014-01-10 4 views

답변

0

다음은 POST 매개 변수를 보낼 수있는 NSURLConnection을 사용하는 예제입니다 :

// Note that the URL is the "action" URL parameter from the form. 
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL @"http://www.whereq.com:8079/answer.m"]]; 
[request setHTTPMethod:@"POST"]; 
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"]; 
//this is hard coded based on your suggested values, obviously you'd probably need to make this more dynamic based on your application's specific data to send 
NSString *postString = @"paperid=6&q77=2&q80=blah"; 
NSData *data = [postString dataUsingEncoding:NSUTF8StringEncoding]; 
[request setHTTPBody:data]; 
[request setValue:[NSString stringWithFormat:@"%u", [data length]] forHTTPHeaderField:@"Content-Length"]; 
[NSURLConnection connectionWithRequest:request delegate:self]; 
+0

감사를 jacob..But 문제가 당신이 알고있다, 나는 [요청의 setValue을 이해할 수 없다 :을 application/x-www-form은-urlencoded를 "@ "forHTTPHeaderField : @"content-type "]; NSString * postString = @ "paperid = 6 & q77 = 2 & q80 = blah"; NSData * data = [postString dataUsingEncoding : NSUTF8StringEncoding]; 이 두 필드 .. 내 코드에 무엇을 써야합니까? –

+0

및 어떤 대리자 메서드를 추가해야합니까 ..? –

관련 문제