我正在开发一个使用来自 Web 服务的数据的应用程序。我尝试使用 afnetworking 3.x 来使用来自 Web 服务的数据。我卡在某个地方。不知道从哪里开始。希望您的帮助。
NSString *mainapiKey = [NSString stringWithFormat:@"12345"];
NSString *urlStringgetairport = [NSString stringWithFormat:@"http://mobileapi.uk/"];
NSURL *getairportUrl = [NSURL URLWithString:urlStringgetairport];
NSMutableURLRequest *finalRequest = [NSMutableURLRequest requestWithURL:getairportUrl];
NSString *soapmessage = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
"<soap:Body>\n"
"<GetAirport xmlns=\"http://mobileapi.uk/\">\n"
"<Authkey>%@</Authkey>\n"
"<AirportCode>%@</AirportCode>\n"
"</GetAirport>\n"
"</soap:Body>\n"
"</soap:Envelope>\n"
,mainapiKey, @""];
NSData *soapdata = [soapmessage dataUsingEncoding:NSUTF8StringEncoding];
NSString *messageLength = [NSString stringWithFormat:@"%lu", (unsigned long)[soapmessage length]];
[finalRequest addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[finalRequest addValue:@"http://mobileapi.uk/GetAirport" forHTTPHeaderField:@"SOAPAction"];
[finalRequest addValue:@"mobileapi.uk" forHTTPHeaderField:@"HOST"];
[finalRequest addValue:messageLength forHTTPHeaderField:@"Content-Length"];
[finalRequest setHTTPMethod:@"POST"];
[finalRequest setHTTPBody:soapdata];
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[manager GET:urlStringgetairport parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSLog(@"output :%@", responseObject);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
}];
webservice输出是一个json
以正常方式成功获取数据