ios - 如何使用 AFNetworking 库调用 .NET XML Web 服务

标签 ios afnetworking

我正在使用以下代码来调用 http://www.highoncoding.com/Customers.asmx网络服务。

更新 1:

现在,我有以下代码:

-(NSMutableArray *) getAll 
{   
    NSURL *baseURL = [NSURL URLWithString:@"http://highoncoding.com/Customers.asmx?op=GetAll"];    

    NSString *soapBody = @"<?xml version=\"1.0\" encoding=\"utf-8\"?><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/\"><soap:Body>    <GetAll xmlns=\"http://tempuri.org/\" /></soap:Body></soap:Envelope>";

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:baseURL];
    [request setHTTPBody:[soapBody dataUsingEncoding:NSUTF8StringEncoding]];

    [request addValue:@"http://tempuri.org/GetAll" forHTTPHeaderField:@"SOAPAction"];

    [request addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];

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

    [operation start];

但不是返回 XML,而是返回 HTML/CSS。

更新 2:

我错过了 httpMethod 行:

[request setHTTPMethod:@"POST"];

最佳答案

您需要将 Content-TypeSOAPAction 设置为 header 。您的 SOAP XML 字符串需要是请求的发布正文。

我建议在使用 AFNetworking 进行随机测试之前,使用 SOAPClient、HTTPClient 或仅使用原始 curl 构建此请求。

将此原始请求与 AFNetworking 生成的请求进行比较,以使用类似 Charles 的代理查看差异所在.

更新:这是一个有效的原始请求示例

HTTP Client issuing the SOAP Request manually

响应:

Response

关于ios - 如何使用 AFNetworking 库调用 .NET XML Web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11210723/

相关文章:

ios - 如何从音频处理中锁定数组以进行分析

ios - 如何使用 Swift 处理 tableView 单元格音频播放和暂停按钮?

ios - 如何创建垂直进度条 - IOS - Swift

ios - AFNetworking - 序列化连接

ios - AFNetworking AFHTTPClient AFJSONRequestOperation 不使用 JSON 操作

ios - Swift按顺序执行异步任务

ios - AFNetworking 能否同步返回数据(在 block 内)?

ios - 没有 Apple 推送通知服务的推送通知?

ios - AFNetworking(POST上出现400错误)

ios - 如何测量兆字节数据量?