gpt4 book ai didi

ios - AFHTTPRequestOperationManager 发布失败

转载 作者:行者123 更新时间:2023-11-29 03:30:04 26 4
gpt4 key购买 nike

我的代码在这里:

AFHTTPRequestOperationManager *managers = [AFHTTPRequestOperationManager manager];

NSMutableDictionary *parDic = [NSMutableDictionary dictionary];

[parDic setObject:@"admin" forKey:@"userId"];

[parDic setObject:@"1" forKey:@"password"];

[managers POST:@"http://posttestserver.com/post.php?" parameters:par success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
NSLog(@"sucess");
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];

它打印出:Error: Error Domain=AFNetworkingErrorDomain Code=-1016 "Request failed: acceptable content-type: text/plain"

但是当我使用厨房测试这个请求时,它工作正常。为什么?请帮助我,非常感谢!

最佳答案

按照下面的代码我成功了

NSString *StringUrl = [NSString stringWithFormat:@"%@?userId=%@&password=%@",YourUrl,@"admin",@"1"];

NSURLRequest *UrlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:StringUrl]];

AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]initWithRequest:UrlRequest];

operation.responseSerializer = [AFJSONResponseSerializer new];

[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *OP,id ResponseObj)
{

NsLog(@"Success == %@",ResponseObj);


}failure:^(AFHTTPRequestOperation *OP,NSError *error)
{

NsLog(@"Error == %@",[error localizedDescription])

}];

[operation start];

关于ios - AFHTTPRequestOperationManager 发布失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19921539/

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