gpt4 book ai didi

ios - AFNetworking 与 put 和 request 主体

转载 作者:行者123 更新时间:2023-11-29 12:36:17 25 4
gpt4 key购买 nike

我尝试发送 put with body,但作为响应,我得到了一个

JSON: {
errorr = "BAD json format";
success = 0;
}

我尝试使用与我的 Rest Web 服务客户端代码中相同的字符串(json 数组),它工作正常,但在我的应用程序中不行

NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys: carID, @"product_id", firstname.text, @"firstname", surname.text, @"lastname", phone.text, @"telephone", email.text, @"email", orderWithUserInfo, @"options", nil];
NSLog(@"JSON: %@", dic);
NSData *jsonData2 = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONReadingMutableContainers error:nil];
NSLog(@"JSON: %@", jsonData2);
NSString *jsonString = [[NSString alloc] initWithData:jsonData2 encoding:NSUTF8StringEncoding];
NSLog(@"jsonData as string:\n%@", jsonString);
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
[manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[manager.requestSerializer setValue:@"application/json;charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
[manager.requestSerializer setValue:@"34987598743" forHTTPHeaderField:@"X-Oc-Merchant-Id"];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
AFHTTPRequestOperation *operationA = [manager PUT:@"http://***/api/rest/addorders" parameters:jsonString success:^(AFHTTPRequestOperation *operation, id responseObject) {

NSLog(@"JSON: %@", responseObject);

//[self showStream:carsList];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {

// 4
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alertView show];
}];

所以我不知道问题出在哪里

最佳答案

我添加了 manager.requestSerializer = [AFJSONRequestSerializer serializerWithWritingOptions:dic]; 它解决了问题

关于ios - AFNetworking 与 put 和 request 主体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26238533/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com