从ios发送soap web服务中的参数

时间:2014-01-27 11:22:35

标签: ios web-services soap

我正在使用SOAP服务将数据从servrer获取到我的ios应用程序。现在我需要从应用程序上传一些数据到server.how我可以从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等参数。

1 个答案:

答案 0 :(得分: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]]

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