-3

我正在肥皂网络服务和 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

你会得到 HTTP 状态码(不是错误码!),didReceiveResponse这显然是一个好兆头。HTTP 状态码 200 表示OK


200 好

请求已成功。响应返回的信息取决于请求中使用的方法,例如:

GET 在响应中发送与请求的资源对应的实体;

HEAD 请求资源对应的实体头字段在响应中发送,不带任何消息体;

POST 描述或包含操作结果的实体;

TRACE 包含终端服务器收到的请求消息的实体。

取自W3 状态代码定义 - rfc2616


继续并httpResponse使用相同的方法将其打印到控制台中。

于 2012-12-25T14:10:22.193 回答