【问题标题】:passing parameter to the web service working code将参数传递给 Web 服务工作代码
【发布时间】:2011-07-31 16:28:31
【问题描述】:

我再次尝试使用肥皂方法,但这次我下载了 charles 并观察了我从我的代码中创建的请求。 Chales 显示“解析数据失败(org.xml.sax.saxparser 异常:prolog 中不允许内容)”

这是我的代码:

 NSString *soapMsg = [[NSString alloc] initWithFormat:@"\n"
                         "\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 addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [req addValue:@"http://tempuri.org/InsertCustomerInformation" forHTTPHeaderField:@"SOAPAction"];
    [req addValue: msgLength forHTTPHeaderField:@"Content-Length"];
    [请求 setHTTPMethod:@"POST"];
    [req setHTTPBody: [soapMsg dataUsingEncoding:NSUTF8StringEncoding]];
    NSLog(@"req....%@", req);
    NSError *错误;
    NSURLResponse *响应;
    //NSData *urlData=[NSURLConnection sendSynchronousRequest:req returnedResponse:&response error:&error];


     NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:req delegate:self];

     如果(连接)
     {
         //webData = [[NSMutableData 数据] 保留];
         NSLog(@"连接正常");
     }
     别的
     {
         NSLog(@"theConnection 为 NULL");
     }





     如果(!响应){
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"连接错误" message:@"无法连接到 Internet" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [警报显示];
        [警报发布];
    }

    别的{
        UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"连接成功" message:@"已连接到 Internet" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert1 显示];
        [alert1 发布];

    }
}


帮助!!提前谢谢!!

【问题讨论】:

  • 尝试删除 SOAP URL 末尾的 op=InsertsCustomerInformation,如果您在服务构造函数中设置断点,您会收到任何信号吗?
  • 请将您的代码和 xml 复制并粘贴到问题中。不是他们的图片。
  • @anna: 实际上代码有标签并且不能正确显示。这就是我附上图片的原因。
  • 在 SO 编辑器中将其视为“代码”。标签会显示得很好。
  • 你构建了一个请求,你实际上在哪里发送任何东西,你从服务中得到什么响应?

标签: iphone


【解决方案1】:

您是在问如何在您的项目中包含 ASIHTTPRequest,对吗?将 ASIHTTPRequest 的文件夹复制并粘贴到您的项目文件夹中,并将其添加到您的代码中:

#import "ASIHTTPRequest.h"

请注意,ASIHTTPRequest 是一个外部库,而不是 iOS SDK 的一部分。

【讨论】:

  • 在哪里可以找到 ASIHTTPRequest 的文件夹??
  • 你能给我发链接吗? .实际上我已经下载了 zip,但是每当我将整个文件夹添加到组和项目中的文件时,它都不起作用。这是链接:allseeing-i.com/ASIHTTPRequest
  • 面临错误:“.objc_class_name_ASIHTTPRequest”,引用自:
  • 嘿!它的工作人员!我能够在我的网络服务中获取参数。谢谢大家帮助我。我要更新我的答案。问题出在我的肥皂信息中。我错过了我的肥皂消息中的一个标签,而且我使用的是 setValue 方法而不是 addValues 方法。
猜你喜欢
  • 2019-05-19
  • 1970-01-01
  • 1970-01-01
  • 2016-09-25
  • 1970-01-01
  • 1970-01-01
  • 2023-03-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多