无法在Web服务中获取参数

时间:2011-04-13 13:23:17

标签: iphone objective-c

  

可能重复:
  get values from text field to webservice

我之前发过类似的问题,但我没有得到适当的帮助!我在重复。我正在从textField上传参数到web服务。一切顺利,但我无法在webservice中检索这些值。 PLZ PLZ帮助!!这是我的代码:

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    NSLog(textView1.text);
    NSString *soapMsg = [[NSString alloc] initWithFormat:@"?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"
                         ""
                         "\n"
                         "%@\n"
                         "%@\n"                                                                                                              
                         "%@\n"
                         "%@\n"
                         "\n"
                         "\n"
                         "\n",str1,str2,str3,str4];                       
        NSLog(soapMsg);

    NSURL *url = [NSURL URLWithString:@"http://192.168.0.218:84/WebServiceCustomerByAmit/Service.asmx?op=InsertCustomerInformation"];
    NSLog(@"url. . . .%@", url);
    NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];    
    NSLog(@"req....%@", req);
    NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMsg length]];


    NSLog(@"msgLength. . .%@", msgLength);
    [req setValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [req setValue:@"http://tempuri.org/InsertCustomerInformation" forHTTPHeaderField:@"SOAPAction"];
    [req setValue:msgLength forHTTPHeaderField:@"Content-Length"];
    [req setHTTPMethod:@"POST"];
    [req setHTTPBody: [soapMsg dataUsingEncoding:NSUTF8StringEncoding]];
    NSLog(@"req....%@", req);
    NSError *error;
    NSURLResponse *response;
    NSData *urlData=[NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&error];
    if(!response){
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Connection Error" message:@"Failed to Connect to the Internet" delegate:self  cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
        [alert release];
    }

    else{
        UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"Connection Successful" message:@"Connected to the Internet" delegate:self  cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert1 show];
        [alert1 release];

    }
}

在gdb中:

2011-04-13 18:40:36.137 uploadToWeb[6018:20b] strings.....ketan 
2011-04-13 18:40:36.138 uploadToWeb[6018:20b] ketan 
2011-04-13 18:40:36.146 uploadToWeb[6018:20b] ?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/">

ketan 
NSr
9463952542
macos



2011-04-13 18:40:36.148 uploadToWeb[6018:20b] url. . . .http://192.168.0.218:84/WebServiceCustomerByAmit/Service.asmx?op=InsertCustomerInformation
2011-04-13 18:40:36.148 uploadToWeb[6018:20b] req....
2011-04-13 18:40:36.148 uploadToWeb[6018:20b] msgLength. . .430
2011-04-13 18:40:36.149 uploadToWeb[6018:20b] req....

web服务:enter image description here

1 个答案:

答案 0 :(得分:0)

使用像Charles这样的HTTP代理来查明您的请求是否确实正确形成。