ios - 在 IOS 中使用 SAOP API 获取 Magento 的 session ID

标签 ios objective-c magento

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\">XXXX</username> \
    <apiKey xsi:type=\"xsd:string\">123456</apiKey> \
    </ns1:login> \
    </SOAP-ENV:Body> \
    </SOAP-ENV:Envelope>";

NSString *url = @"http://xxx.xxx.xx.xxx/Magento/api/soap/?wsdl";


    [urlConnection urlConnection:soapMessage url:url];
    [urlConnection setTarget:self withValidSelector:@selector(jsonData:) invalidSelector:@selector(error)];

In urlConnection

    NSURL *url = [NSURL URLWithString:urlString];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    NSString *msgLength = [NSString stringWithFormat:@"%d",[postString length]];
    [request addValue:@"application/soap+xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [request addValue:@"xxx.xxx.xx.xxx/magento/" forHTTPHeaderField:@"SOAPAction"];
    [request addValue:msgLength forHTTPHeaderField:@"Content-Length"];
    [request setHTTPMethod:@"POST"];
    [request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];

上面是我的代码。它返回大量带有 html 而不是 SESSION ID 的 XML 标记。

最佳答案

从您的网址“http://xxx.xxx.xx.xxx/Magento/api/soap/?wsdl”中删除“?wsdl”。

使用了这个 url "http://xxx.xxx.xx.xxx/Magento/api/soap/ "

它将返回 SESSION ID。

关于ios - 在 IOS 中使用 SAOP API 获取 Magento 的 session ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26273151/

相关文章:

ios - 如何添加 pod 0.3.3

mysql - 如何获取此类错误的表 - SQLSTATE [23000] : Integrity constraint violation: 1062

magento - 将产品添加到购物车之前如何在 magento 产品 View 中应用优惠券

ios - 如何知道 UIViewController 的 subview 何时被删除?

ios - 我应该如何在 iOS 项目中存储本地化字符串?

objective-c - Xcode 4.2和ARC的iOS AVAudioPlayer双重声音播放问题

ios - 尝试将 Web 服务中的值保存到核心数据中

magento - magento 中联系我们的时事通讯选项

iphone - UINavigationController - 基础知识

objective-c - 执行 Facebook 查询时没有返回结果