2014-11-13 6 views
0

afnetworking 2.0을 사용하여 URL에 데이터를 보내려고합니다. 매개 변수로 사전 값을 전달하고 있습니다. 다음 코드는 내 코드입니다.Afnetworking 2.0 게시 메서드 오류

NSError * error; NSData * executionsData = [NSJSONSerialization dataWithJSONObject : dic 옵션 : NSJSONWritingPrettyPrinted 오류 : & 오류];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"my url"]]; 
[request setTimeoutInterval:600]; 
[request setHTTPMethod:@"POST"]; 
[request setValue:[NSString stringWithFormat:@"%lu", (unsigned long)executionsData.length] forHTTPHeaderField:@"Content-Length"]; 
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; 
[request setHTTPBody:executionsData]; 
[request setValue:[self userAgent] forHTTPHeaderField:@"User-Agent"]; 


AFHTTPRequestOperation *op = [[AFHTTPRequestOperation alloc] initWithRequest:request]; 
op.responseSerializer = [AFJSONResponseSerializer serializer]; 

[op setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { 
    NSDictionary* resultsDict = (NSDictionary*)responseObject; 
    NSLog(@"%@", resultsDict); 
    //process result json dictionary 

    //success 
    //success(); 
} failure:^(AFHTTPRequestOperation *operation, NSError *error) { 
    //failure 
    NSLog(@"Error:%@",error); 
    //failure(); 
}]; 

하지만이 코드를 실행할 때마다 아래와 같은 오류가 표시됩니다.

도메인 = com.alamofire.error.serialization.response 코드 = -1011 "요청하지 못함 : 잘못된 요청 (400)"UserInfo = 0x8c46db0 {com.alamofire.serialization.response.error.response = {URL : 내 URL } {상태 코드 : 400, 헤더 { 연결 = 닫기; "Content-Language"= ko; "Content-Length"= 968; "Content-Type"= "text/html; charset = utf-8"; 날짜 = "Thu, 2014 년 11 월 13 일 08:52:14 GMT"; 서버 = "Apache-Coyote/1.1"; 가}} NSErrorFailingURLKey 내 URL을 =, NSLocalizedDescription = 요청이 실패했습니다 : com.alamofire.serialization.response.error.data = < 3c68746d 6c3e3c68 3c746974 6c653e41 70616368 6520546f 6d636174 2f372e30 2e353420 2d204572 726f7220 7265706f 72743c2f 7469746c 653e3c73 74796c65 6561643e 잘못된 요청 (400) 3e3c212d 2d483120 7b666f6e 742d6661 6d696c79 3a546168 6f6d612c 41,726,961 6c2c7361 6e732d73 65,726,966 3b636f6c 6f723a77 68,697,465 3b626163 6b67726f 756e642d 636f6c6f 723a2335 32,354,437 363b666f 6e742d73 697a653a 32,327,078 3b7d2048 32207b66 6f6e742d 66616d69 6c793a54 61686f6d 612c4172 69616c2c 73616e73 2d736572 69663b63 6f6c6f72 3a776869 74653b62 61636b67 726f756e 642d636f 6c6f723a 23,353,235 4437363b 666f6e74 2d73697a 653a3136 70783b7d 20,483,320 7b666f6e 742d6661 6d696c79 3a546168 6f6d612c 41726961 6c2c7361 6e732d73 65726966 3b636f6c 6f723a77 68697465 3b626163 6b67726f 756e642d 636f6c6f 723a2335 32354437 363b666f 6e742d73 697a653a 31347078 3b7d2042 4f445920 7b666f6e 742d6661 6d696c79 3a546168 6f6d612c 41,726,961 6c2c7361 6e732d73 65,726,966 3b636f6c 6f723a62 6c61636b 3b626163 6b67726f 756e642d 636f6c6f 723a7768 6974653b 7d204220 7b666f6e 742d6661 6d696c79 3a546168 6f6d612c 41,726,961 6c2c7361 6e732d73 65,726,966 3b636f6c 6f723a77 68,697,465 3b626163 6b67726f 756e642d 636f6c6f 723a2335 32,354,437 363b7d20 50207b66 6f6e742d 66616d69 6c793a54 61686f6d 612c4172 69616c2c 73616e73 2d736572 69663b62 61636b67 726f756e 643a7768 6974653b 636f6c6f 723a626c 61636b3b 666f6e74 2d73697a 653a3132 70783b7d 41207b63 6f6c6f72 203a2062 6c61636b 3b7d412e 6e616d65 207b636f 6c6f7220 3a20626c 61636b3b 7d485220 7b636f6c 6f72203a 20,233,532 35,443,736 3b7d2d2d 3e3c2f73 74796c65 3e203c2f 68,656,164 3e3c626f 64793e3c 68313e48 54,545,020 53,746,174 75,732,034 3030202d 203c2f68 313e3c48 52,207,369 7a653d22 3122206e 6f736861 64653d22 6e6f7368 61,646,522 3e3c703e 3c623e74 7970653c 2f623e20 53746174 75732072 65706f72 743c2f70 3e3c703e 3c623e6d 65737361 67653c2f 623e203c 753e3c2f 753e3c2f 7 03e3c70 3e3c623e 64,657,363 72,697,074 696f6e3c 2f623e20 3c753e54 68,652,072 65,717,565 73,742,073 656e7420 62,792,074 68,652,063 6c69656e 74,207,761 73,207,379 6e746163 74,696,361 6c6c7920 696e636f 72,726,563 742e3c2f 753e3c2f 703e3c48 52,207,369 7a653d22 3122206e 6f736861 64653d22 6e6f7368 61,646,522 3e3c6833 3e417061 63,686,520 546f6d63 61742f37 2e302e35 343c2f68 333e3c2f 626f6479 3e3c2f68 746d6c3e> NSUnderlyingError = 0x8c1e0e0 "요청이 실패 : 용납 될 수없는 content-type : text/html "}

나는 IOS에 익숙하지 않으며 afnetworking에 대해 많이 모른다. 아무도 이것에 대한 재연이 있습니까?

답변

0

AFHTTPSessionManager 및 그 방법 POST:parameters:success:failure:을 사용하십시오. 여기에 더 많은 예제가 있습니다 : http://www.raywenderlich.com/59255/afnetworking-2-0-tutorial 아래 라이브 서비스에 후크 제목.

+0

afhttpsessionmanager를 사용하여 수행 할 때 동일한 오류가 발생했습니다. –

+0

sessionManager에서 paramiteres에 NSDictionary 대신 NSDictionary를 제공해야합니다. – MMiroslav

+1

내 코드에서 사전을 매개 변수로 제공했습니다. 사용하지 않습니다. –