【问题标题】:iOS: How do i send array to soap xml with "customerCustomerCreate" in magento apiiOS:我如何在magento api中使用“customerCustomerCreate”将数组发送到soap xml
【发布时间】:2014-10-16 08:53:08
【问题描述】:

如何在 magenta api 中使用“customerCustomerCreate”将数组发送到soap xml,我将以下soap 消息发送到magento api:-

这是我的目标 c 代码:

NSString *soapMessage = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\
                         <SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns1=\"urn:Magento\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"> \
                         <SOAP-ENV:Body> \
                         <ns1:customerCustomerCreate> \
                         <sessionId xsi:type=\"xsd:string\">%@</sessionId> \
                         <customerData xsi:type=\"xsd:string\">%@</customerData> \
                         </ns1:customerCustomerCreate> \
                         </SOAP-ENV:Body> \
                         </SOAP-ENV:Envelope>",sessionId,newCustomerArray];

NSURL *url = [NSURL URLWithString:@"http://www.modavive.com/index.php/api/v2_soap/"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%lu",(unsigned long)[soapMessage length]];
[request addValue:@"application/soap+xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[request addValue:@"urn:Mage_Api_Model_Server_V2_HandlerAction/customerCustomerCreate" forHTTPHeaderField:@"SOAPAction"];
[request addValue:msgLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if(connection){
    webData = [NSMutableData data];
}
else
    NSLog(@"theConnection is null");   

这是我的数组:-

(
 {
     customerCustomerEntityToCreate = {
         email = "test@gmail.com";
         firstname = John;
         gender = 1;
         "group_id" = 1;
         lastname = joe;
         password = 1234;
         "store_id" = 1;
         "website_id" = 1;
     };
 }
 )

并得到以下错误:-

<?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>100</faultcode><faultstring>Customer email is required</faultstring></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>

我用谷歌搜索了很多,但仍然没有得到任何解决方案,请帮助我。

提前致谢

【问题讨论】:

  • 到目前为止有什么解决方案吗?

标签: ios objective-c magento soap


【解决方案1】:

Megento 文档不适用于 IOS,或者我们误读了它尝试发送简单的键值忘记他们在那里提到的数组,它会起作用

soapMessage = [soapMessage stringByAppendingFormat:@"<customerCustomerCreate>"]; 
soapMessage = [soapMessage stringByAppendingString:@"<customerData>"];
soapMessage = [soapMessage stringByAppendingFormat:@"<email>%@</email>" ,email_string];
soapMessage = [soapMessage stringByAppendingFormat:@"<firstname>%@</firstname>" ,fname_string];
soapMessage = [soapMessage stringByAppendingFormat:@"<lastname>%@</lastname>" ,lname_string];
soapMessage = [soapMessage stringByAppendingFormat:@"<password>%@</password>" ,password_string];
soapMessage = [soapMessage stringByAppendingString:@"<website_id>1</website_id>"];
soapMessage = [soapMessage stringByAppendingString:@"<store_id>1</store_id>"];
soapMessage = [soapMessage stringByAppendingString:@"<group_id>1</group_id>"];
soapMessage = [soapMessage stringByAppendingString:@"</customerData>"];
soapMessage = [soapMessage stringByAppendingFormat:@"</customerCustomerCreate>"];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-03
    • 2018-08-31
    • 1970-01-01
    • 1970-01-01
    • 2011-09-25
    • 1970-01-01
    相关资源
    最近更新 更多