I use the following code to make a first call to the magento webservice, it is a login (I used this doc)
我使用以下代码首次调用magento webservice,它是一个登录(我用过这个doc)
NSString *soapMessage = @" \
<?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:login> \
<username xsi:type=\"xsd:string\">user</username> \
<apiKey xsi:type=\"xsd:string\">password</apiKey> \
</ns1:login> \
</SOAP-ENV:Body> \
</SOAP-ENV:Envelope>";
NSURL *url = [NSURL URLWithString:@"http://localhost/magentoPath/api/soap/?wsdl"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d",[soapMessage length]];
[request addValue:@"application/soap+xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[request addValue:@"localhost/magentoPath/" 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){
self.webData = [NSMutableData data];
}
else
NSLog(@"theConnection is null");
later on I have the following method which logs the response I get. The problem is, I always get the content of the wsdl, but I should get a session ID from magento. What am I making wrong? Thanks!
稍后,我有以下方法记录我得到的响应。问题是,我总是得到wsdl的内容,但我应该从magento获得会话ID。我弄错了什么?谢谢!
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"Done. received Bytes %d", [self.webData length]);
NSString *xml = [[NSString alloc] initWithBytes:[self.webData mutableBytes] length:[self.webData length] encoding:NSUTF8StringEncoding];
NSLog(xml);
}
By the way, the request xml is from PHP's SoapClient where the login works correctly. So it has nothing todo with Magento.
顺便说一下,请求xml来自PHP的SoapClient,登录正常。所以它与Magento毫无关系。
2 个解决方案
#1
1
So I found the solution myself after looking into the logs of magento. It says that you don't need to declare the xml every time, so just delete
所以我在查看magento的日志后自己找到了解决方案。它说你不需要每次都声明xml,所以只需要删除
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
from the request and it works!
从请求,它的工作原理!
#2
0
The trailing '?wsdl'
makes the service return its WSDL definition. If you leave that out, you'll actually call the service.
尾部'?wsdl'使服务返回其WSDL定义。如果你把它留下来,你实际上会打电话给服务。
#1
1
So I found the solution myself after looking into the logs of magento. It says that you don't need to declare the xml every time, so just delete
所以我在查看magento的日志后自己找到了解决方案。它说你不需要每次都声明xml,所以只需要删除
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
from the request and it works!
从请求,它的工作原理!
#2
0
The trailing '?wsdl'
makes the service return its WSDL definition. If you leave that out, you'll actually call the service.
尾部'?wsdl'使服务返回其WSDL定义。如果你把它留下来,你实际上会打电话给服务。