-3

SOAP Web サービスと iOS アプリ間で接続を行っており、接続は完了していますが、HTTP 200 というエラーが発生します。

このエラーを解決するにはどうすればよいですか?


コード

-(IBAction)buttonClick:(id)sender
{
    dig = @"م ط ر" ;
    cha =@"0158";

    NSString *soapMessage = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                             "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">"
                             "<s:Body>"
                             "<GetCarDataByPlate xmlns=\"http://tempuri.org/\">"
                             "<params>"
                             "<PlateDigits>%@</PlateDigits>"
                             "<PlateStr>%@</PlateStr>"
                             "<Pass>Mob.2013</Pass>"
                             "</params>"
                             "</GetCarDataByPlate>"
                             "</s:Body>"
                             "</s:Envelope>",dig,cha];

    NSLog(@"%@", soapMessage);

    NSURL *url = [NSURL URLWithString:@"http://www.uis.com.sa/Wcf_MobileS/MobileService.svc?wsdl"];

    NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];

    NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];

    [theRequest addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [theRequest addValue:@"http://tempuri.org/IMobileService/GetCarDataByPlate" forHTTPHeaderField:@"SOAPAction"];
    [theRequest addValue:msgLength forHTTPHeaderField:@"Content-Length"];
    [theRequest setHTTPMethod:@"POST"];
    [theRequest setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];





    NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
    NSLog(@"theConnection = %@",theConnection);


    if(theConnection)
    {
        webData = [NSMutableData data];
        NSLog(@"WebData = %@",webData);

    }
    else
    {
        NSLog(@"theConnection is null");
    }

}

-(void)connection:(NSURLConnection*)connection didReceiveResponse:(NSURLResponse*)response
{
    [webData setLength:0];
    NSHTTPURLResponse * httpResponse;

    httpResponse = (NSHTTPURLResponse *) response;

    NSLog(@"HTTP error %zd", (ssize_t) httpResponse.statusCode);

}

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData*)data
{
    [webData appendData:data];
  //  NSLog(@"webdata: %@", data);

}

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError*)error
{
    NSLog(@"error with the connection");
}

-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    NSLog(@"DONE. Received bytes %d", [webData length]);
    NSString *theXML = [[NSString alloc] initWithBytes:[webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
    NSLog(@"xml %@",theXML);
}
4

1 に答える 1

2

didReceiveResponse明らかに良い兆候であるHTTP ステータス コード (エラー コードではありません!) を取得します。HTTP ステータスコード 200 はOKを意味します。


200OK

リクエストは成功しました。応答で返される情報は、要求で使用されるメソッドによって異なります。たとえば、次のようになります。

GET 要求されたリソースに対応するエンティティが応答で送信されます。

HEAD 要求されたリソースに対応するエンティティ ヘッダー フィールドは、メッセージ本文なしで応答で送信されます。

アクションの結果を記述または含むエンティティを POST します。

エンド サーバーが受信した要求メッセージを含むエンティティをトレースします。

W3 Status Code Definitions - rfc2616から取得。


先に進んhttpResponseで、まったく同じメソッド内からコンソールに出力してください。

于 2012-12-25T14:10:22.193 に答える