2012-09-20 1 views
2

내 URL은 정확하지만 요청이 잘못되었습니다. 나는 400을 얻고있다. 어떤 아이디어? API 문서에서는 JSON 본문 대신 매개 변수가 전달 된 경우 400을 반환 할 수 있다고 말합니다. 미리 감사드립니다. 10 : 54.732 RingDNA 무료 AFNetworking (POST시 400 오류)

2012년 9월 19일 18

: [6018을 : C07] __47- [ChatterHelper postFeedItem : 응답 : 실패 :] ​​_ block_invoke_087 [

- (void)postFeedItem:(NSDictionary *)paramDict Response:(void (^)(id))callbackBlock Failure:(void (^)())failure { 

NSString *targetUrl = [NSString stringWithFormat:@"%@/services/data/v23.0/chatter/feeds/user-profile/%@/", _appManager.coordinator.credentials.instanceUrl, [_appManager.userInformation objectForKey:@"sfUserId"]]; 

AFHTTPClient *client = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:targetUrl]]; 
/* 
{ "body" : 
{ 
Request body example: 
"messageSegments" : [ 
{ 
"type": "Text", 
"text" : "New post" 
} 
] 
} 
} 
*/ 

NSArray *arr = [NSArray arrayWithObjects: 
       [NSDictionary dictionaryWithObjectsAndKeys:@"Text", @"type", 
       @"New post", @"text", 
       nil], 
       nil]; 
NSDictionary* info = [NSDictionary dictionaryWithObjectsAndKeys: 
         [NSDictionary dictionaryWithObjectsAndKeys:arr, @"messageSegments", nil], 
         @"body", 
         nil]; 

NSLog(@"JSON: %@", [[NSString alloc] initWithData:[self toJSON:info] encoding:NSUTF8StringEncoding]); 

NSMutableURLRequest *request = [client multipartFormRequestWithMethod:@"POST" path:@"feed-items" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) { 
    [formData appendData:[self toJSON:info]]; 
}]; 

[request setValue:[NSString stringWithFormat:@"OAuth %@",_appManager.coordinator.credentials.accessToken] forHTTPHeaderField:@"Authorization"]; 
[request addValue:@"false" forHTTPHeaderField:@"X-Chatter-Entity-Encoding"]; 
[request addValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; 

AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) { 
    NSLog(@"success"); 
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) { 
    NSLog(@"FAILED CHATTER Request: %@ - %@ - %@", [request URL], [request allHTTPHeaderFields], error.description); 
}]; 

[operation start]; 

} 여기

는 NSLog의 라인 76] FAILED CHATTER 요청 : https://na4.salesforce.com/services/data/v23.0/chatter/feeds/user-profile/00560000001j3paAAA/feed-items - { "Accept-Encoding"= gzip; "Accept-Language"= "en, fr, de, ja, nl, it, es, pt, pt-PT, da, fi, nb, sv, ko, zh-Hans, zh- tr, uk, ar, hr, cs, el, he, ro, sk, th, id, ms, en-GB, ca, hu, vi, en-us; q = 0.8 "; 인증 = "OAuth 00D60000000KV29! ARkAQFWhnhOtcGFgVMT4MkZHCV3zG9SY4en66718BiG_ZY59W0gR1iSWA8i.ey_b94vqjRW_RQITALBWmfpPrKTGk"; "Content-Type"= "다중 파트/양식 데이터, 경계 = 경계 + 0xAbCdEfGbOuNdArY, application/json"; "User-Agent"= "com.ringdna.dreamforce.RingDNA-Free/36 (알 수 없음, iPhone OS 5.1, iPad 시뮬레이터, 크기/1.000000)"; "X-Chatter-Entity-Encoding"= 거짓;} - 오류 도메인 = com.alamofire.networking.error 코드 = -1011 "예상되는 상태 코드 [인덱스 수 : 100 (1 범위), 인덱스 : (200-299)], 400"UserInfo = 0xa2a8b40 {NSErrorFailingURLKey = https : //na4.salesforce.com/services/data/v23.0/chatter/feeds/user-profile/00560000001j3paAAA/feed-items, NSLocalizedDescription = 예상 상태 코드 [인덱스 수 : 100 (1 범위 내), 색인 : (200-299)], 얻은 400}

+0

심지어 새 응용 프로그램을 만들 수 없습니다 이니이 다른 사람 도움이된다면 채팅 게시물을 작업을위한 코드 샘플은 지금 Github에서에 있습니다. 내 이름 아래에 '설정'링크가 없습니다. 저를 도와주세요. –

답변