3

次のコードを使用して、http://www.highoncoding.com/Customers.asmx Web サービスを呼び出しています。

更新 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"];
4

1 に答える 1

7

Content-TypeSOAPActionをヘッダーとして設定する必要があります。SOAP XML 文字列は、リクエストの投稿本文である必要があります。

AFNetworking を使用してランダムなスタブを取得する前に、SOAPClient、HTTPClient、または raw curl を使用してこのリクエストを作成することをお勧めします。

Charlesのようなプロキシを使用して、この生のリクエストを AFNetworking によって生成されたリクエストと比較して、どこに違いがあるかを確認します。

更新:これは、機能する生のリクエストの例です

SOAP リクエストを手動で発行する HTTP クライアント

そして応答:

応答

于 2012-06-26T18:07:33.143 に答える