【发布时间】:2017-02-13 17:04:58
【问题描述】:
这是我向服务器发送请求的方式:
- (void)searchForText:(NSString *)searchText scope:(NSInteger)scopeOption
{
[SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
[SVProgressHUD showWithStatus:@"Getting Data"];
NSString *string = [NSString stringWithFormat:@"%@/API/ICD10Code/1",BaseURLString];
NSDictionary *para = @{@"Code":searchText};
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
NSMutableURLRequest *req = [[AFJSONRequestSerializer serializer] requestWithMethod:@"PUT" URLString:string parameters:para error:nil];
NSString *token = [NSString stringWithFormat:@"Bearer %@",[[NSUserDefaults standardUserDefaults] objectForKey:@"userToken"]];
[req setValue:token forHTTPHeaderField:@"Authorization"];
NSLog(@"URL is: %@ Parameters: %@ Token: %@",string, para, token);
[[manager dataTaskWithRequest:req completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error){
if (!error) {
if (response) {
NSLog(@"Response is: %@",response);
[SVProgressHUD dismiss];
}
} else {
// NSLog(@"Error: %@, %@, %@", error, response, responseObject);
NSLog(@"Error: %@", error.localizedDescription);
[SVProgressHUD dismiss];
SCLAlertView *alert = [[SCLAlertView alloc] init];
[alert showError:self title:@"Error"
subTitle:[NSString stringWithFormat:@"%@",[responseObject objectForKey:@"Message"]]
closeButtonTitle:@"OK" duration:0.0f];
}
}] resume];
}
当我运行代码时,NSLog 的响应给了我:
响应是:{ URL: http://ts-test01/app/API/ICD10Code/1 } { 状态码:200,标题 { “缓存控制”=“无缓存”; “内容长度”= 1525; “内容类型”=“应用程序/json;字符集=utf-8”; 日期 =“格林威治标准时间 2016 年 10 月 5 日星期三 09:50:15”; 过期=“-1”; Pragma = "无缓存"; 服务器 = "Microsoft-IIS/8.0"; “X-AspNet-版本”=“4.0.30319”; "X-Powered-By" = "ASP.NET"; } }
但后端人员正在获取数据。我在发送请求时做错了什么。
【问题讨论】:
-
你是对的
标签: ios objective-c afnetworking-3