【问题标题】:send parameter in soap web service from ios从ios在soap web服务中发送参数
【发布时间】:2014-01-27 20:15:25
【问题描述】:

我正在使用 SOAP 服务将数据从服务器获取到我的 ios 应用程序。现在我需要将一些数据从应用程序上传到服务器。我怎样才能从 SOAP 消息中做到这一点。这是我的 SOAP 服务。

POST /NoteService.asmx HTTP/1.1
Host: ios.myurl.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.myurl.com/CreateNoteUsingXMl"   

<?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/">
  <soap:Body>
    <CreateNoteUsingXMl xmlns="http://www.myurl.com">
  <AccountID>string</AccountID>
  <Username>string</Username>
  <Mypass>string</Mypass>
  <NoteXML>string</NoteXML>
  <isSign>int</isSign>
  <noteID>long</noteID>
</CreateNoteUsingXMl>
</soap:Body>
</soap:Envelope>

如何在 POST 中传递 accountid、username 等参数。

【问题讨论】:

    标签: ios web-services soap


    【解决方案1】:

    这很容易创建一个 NSString

    NSString *soapMessage = [NSString stringWithFormat:
                             @"<?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"
                             "<soap:Body>\n"
                             "<CreateNoteUsingXMl xmlns="http://www.myurl.com">\n"
                              " <Username>%@</Username>\n"
                              "<Mypass>%@</Mypass>\n"
                              "<NoteXML>%@</NoteXML>\n"
                             "</CreateNoteUsingXMl>\n"
                             "</soap:Body>\n"
                             "</soap:Envelope>\n"
                             ,username
                             , mypassword
                             , notexml
                             ];
    

    现在创建NSURL

    NSURL *url = [NSURL URLWithString:@"What Ever"];
    

    创建NSMutableURLRequest

    NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
    NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
    
    
    [theRequest setHTTPMethod:@"POST"];
    [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]]
    

    做你想做的其他事情......

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-04
      • 1970-01-01
      相关资源
      最近更新 更多