【发布时间】:2012-03-26 10:54:46
【问题描述】:
iPhone 应用程序中的 Magento Web 服务(Magento 版本 1.6.0.0)有问题。实际上,我可以使用此代码(产品列表代码)登录并获得产品列表:-
NSMutableString *parameters = [NSMutableString stringWithFormat:@"<sessionId>%@</sessionId><resourcePath>%@</resourcePath>", session, @"product.list"];
NSString *operation=[NSString stringWithString:@"call"];
NSString *xmlNamespace=[NSString stringWithString:storeWsdlLink];
NSString *adress=[NSString stringWithString:storeURL];
NSString *operatorTag = [NSString stringWithFormat:@"<%@ xmlns=\"%@\">%@</%@>\n", operation, xmlNamespace, parameters, operation];
NSString *soapMessage = [NSString stringWithFormat:
@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<s:Envelope xmlns:a=\"http://www.w3.org/2005/08/adressing\" xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\">\n"
" <s:Header>\n"
" <To xmlns=\"http://www.w3.org/2005/08/adressing\">%@</To>\n"
" <a:Action>http://tempuri.org/IService1/%@</a:Action>\n"
" </s:Header>\n"
" <s:Body>\n"
" %@"
" </s:Body>\n"
"</s:Envelope>\n", adress, operation, operatorTag
];
ASIHTTPRequest *asiRequest = [[ASIHTTPRequest alloc]initWithURL:[NSURL URLWithString:adress]];
[asiRequest setDelegate:self];
[asiRequest setURL:[NSURL URLWithString:adress]];
[asiRequest setTimeOutSeconds:30];
[asiRequest addRequestHeader:@"application/soap+xml; charset=utf-8" value:@"Content-Type"];
[asiRequest setRequestMethod:@"POST"];
[asiRequest setPostBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
[asiRequest startAsynchronous];
如果我将“parameters”替换为:-
parameters = [NSMutableString stringWithFormat:@"<sessionId>%@</sessionId><resourcePath>%@</resourcePath><sku>%i</sku>", session, @"product.info", 12345];
我收到“Product not exists.”错误消息和“101”代码错误。
在一些论坛中,他们建议在“12345”(产品的 SKU)之后添加一个空格,但这不起作用。
感谢您的帮助。
编辑:-
我使用 PHP 调用 Magento Web 服务,它可以工作:-
$proxy = new SoapClient('xxx/api/?wsdl');
$sessionId = $proxy->login('userName', 'apiKey');
echo json_encode($proxy->call($sessionId, 'product.info', 111));
所以现在我确定问题出在我的代码中。
问题(我认为)是参数部分( --> <sku>%i</sku>
有什么想法吗?
【问题讨论】:
标签: iphone web-services api magento