1

我正在尝试从我的 iPhone 应用程序中使用 SOAP Web 服务,但是当我与 Charles 核对时出现以下错误:

值不能为空。参数名称:s

以下是我的代码:

NSString *soapMessage = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?><SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"><SOAP-ENV:Body><updateTimesheet><TimeSheetHourID>222</TimeSheetHourID></updateTimesheet></SOAP-ENV:Body></SOAP-ENV:Envelope>"];

NSURL *url = [NSURL URLWithString:@"http://172.xx.xxx.xx:xxxx/postService.svc/basic"];

NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];


NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
NSLog(@"Message Length..%@",msgLength);

[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"urn:IpostService/updateTimesheet" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

NSHTTPURLResponse* urlResponse = nil;
NSError *error = [[NSError alloc] init];
//NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

NSData *responseData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&urlResponse error:&error];
NSString *result = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(@"Response Code: %d", [urlResponse statusCode]);
if ([urlResponse statusCode] >= 200 && [urlResponse statusCode] < 300) {
    NSLog(@"Response: %@", result);
    //here you get the response 
}

我收到错误代码 500 作为响应。有人可以帮帮我吗?

谢谢潘卡伊
_

4

2 回答 2

0

问题不在于您的代码。我建议您跟踪网络服务代码。

于 2012-02-08T13:31:34.913 回答
0

错误 500 是 - 内部服务器错误。这意味着 - 服务器遇到了阻止它完成请求的意外情况。

确保您正在向您的服务器发送正确的请求。你能在其他地方消费吗?

于 2012-02-08T12:41:03.710 回答