進出口使用Salesforce的現場代表REST API在iOS應用,試圖請求聊天,但總是失敗,400的請求是無效ChasitorInitAfnetworking - 後JSON - > 400錯誤的請求
NSDictionary *parameters [email protected]{ @"SessionId" :self.sessionId,
@"OrganizationId" :ORG_ID,
@"deploymentId" :DEPLOYEMENT_ID,
@"buttonId" :BUTTON_ID,
@"userAgent" :USER_AGENT,
@"language" :LANG,
@"screenResolution" :SCREEN_RES,
@"visitorName" :@"Test Visitor",
@"prechatDetails" :@[],
@"prechatEntities" :@[],
@"receiveQueueUpdates":@"true",
@"isPost" :@"true"
};
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
AFJSONRequestSerializer *serializer = [AFJSONRequestSerializer serializer];
[serializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[serializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
manager.requestSerializer = serializer;
[manager.requestSerializer setValue:self.sessionKey forHTTPHeaderField:X_LIVEAGENT_SESSION_KEY];
[manager.requestSerializer setValue:@"null" forHTTPHeaderField:X_LIVEAGENT_AFFINITY];
[manager.requestSerializer setValue:@"1" forHTTPHeaderField:X_LIVEAGENT_SEQUENCE];
[manager.requestSerializer setValue:API_V forHTTPHeaderField:X_LIVEAGENT_API_VERSION];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
[manager POST:ChasitorInit_path parameters:parameters progress:nil
success:^(NSURLSessionDataTask *task, id responseObject) {
NSError* error;
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseObject
options:kNilOptions
error:&error];
} failure:^(NSURLSessionDataTask *task, NSError *error) {
NSLog(@"Error: %@", error);
}];
進出口使用Afnetworking V3 iOS8上 請求體應該是
{
"sessionId": "8f1cfb18-fbd1-4487-90d-e98c0a84e165",
"organizationId": "00D58000000OwMB",
"deploymentId": "57258000000L1mj",
"buttonId": "57358000000L24F",
"userAgent": "",
"language": "en-US",
"screenResolution": "1900x1080",
"visitorName": "Test Visitor",
"prechatDetails": [],
"prechatEntities": [],
"receiveQueueUpdates": true,
"isPost": true
}
我做什麼我錯了? PLZ糾正我!
感謝您的答覆,我更新的問題,請參見PARAMS生成的JSON – Gilber
更換後有什麼錯誤@ 「prechatDetails」:@ {},由@ 「prechatDetails」:@ [], –
改變現在出現錯誤「字符0周圍的值無效」。 – Gilber