肥皂主体
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"
" <Ins_VIP xmlns=\"http://tempuri.org/>\">\n"
"<strVIPNo>%@</name>\n"
"</name>\n"
"</soap:Body>\n"
"</soap:Envelope>\n" , str];
这是一个简单的 soap 消息,你知道。如果我想使用我如何构造它的函数传递 str 的值?
但是,我想为这个对象传递值,这怎么可能呢?
最佳答案
你可以这样做,你必须根据你的要求进行修改:
//Add Request key and Values in below arrays
NSArray* ReqKeyList;
NSArray* ReqValueList;
NSString *HeaderPart;
NSString *BodyPart = @"";
NSString *FooterPart;
NSString *soapMessage;
HeaderPart = [NSString stringWithFormat:@"<%@ xmlns=\"http://tempuri.org/\">\n",YourFunctionName];
FooterPart = [NSString stringWithFormat:@"</%@>\n", YourFunctionName];
for(int i=0;i<ReqKeyList.count;i++)
{
if (ReqValueList.count>i){
BodyPart = [BodyPart stringByAppendingString:[NSString stringWithFormat:@"<%@>%@</%@>\n",ReqKeyList[i],ReqValueList[i],ReqKeyList[i]]];
}
}
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"
"%@"
"%@"
"%@"
"</soap:Body>\n"
"</soap:Envelope>\n",HeaderPart,BodyPart,FooterPart];
关于ios - 如何在 objective-c 中创建动态 SOAP 信封,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35980742/