gpt4 book ai didi

ios - AFHTTPRequestOperationManager POST 请求因网络连接丢失而失败 (-1005)

转载 作者:可可西里 更新时间:2023-11-01 04:52:17 26 4
gpt4 key购买 nike

我的服务器端是使用 DJango 服务作为 API 的谷歌计算引擎

这是我在 xcode IOS 6.1 中运行的代码

static NSString *const BaseURLString = @"http://myUrl/";

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
[manager POST:BaseURLString
parameters:[self getParameters]
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSArray *returnedData = (NSArray *)responseObject;
[self doSomething:returnedData];
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"Error Retrieving Properties" message:[NSString stringWithFormat:@"%@", error] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[av show];
}];

它总是失败并显示 Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost." 但是当我使用 curl -datacurl --data 从终端调用服务时param1=1&param2=3"http://myUrl/ 完美运行

最佳答案

试试这个:

   NSURL *url = [NSURL URLWithString:BaseURLString];

而不是

   [manager POST:BaseURLString parameters:[self getParameters]
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSArray *returnedData = (NSArray *)responseObject;
[self doSomething:returnedData];

使用

   [manager POST:url parameters:[self getParameters]
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSArray *returnedData = (NSArray *)responseObject;
[self doSomething:returnedData];

关于ios - AFHTTPRequestOperationManager POST 请求因网络连接丢失而失败 (-1005),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20504361/

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