使用kso​​ap2从magento Web服务获取会话ID时出错

时间:2015-02-25 11:41:06

标签: android magento android-ksoap2

private static final String NAMESPACE = "urn:Magento";
private static final String URL = "http://example.com/api/v2_soap";
private static final String METHOD="login";
private static final String ACTION="urn:Magento/login";
String sessionId,error;   

    try {
        SoapObject request = new SoapObject(NAMESPACE, METHOD);

        request.addProperty("username", "xxxxxx");
        request.addProperty("apiKey", "xxxxxx");

        SoapSerializationEnvelope env = new SoapSerializationEnvelope(SoapEnvelope.VER11);

        env.dotNet = true;
        env.xsd = SoapSerializationEnvelope.XSD;
        env.enc = SoapSerializationEnvelope.ENC;

        env.setOutputSoapObject(request);

        AndroidHttpTransport androidHttpTransport=new AndroidHttpTransport(URL);            
        androidHttpTransport.debug=true;
        androidHttpTransport.call("", env);

        Object res = env.getResponse();
        sessionId=res.toString();
        Log.v("sessionId", sessionId);

        }catch (Exception e){
            error=e.getMessage();
            Log.v("Soapfault",error);
        }

这是我正在使用的代码。我收到SocketTimeoutException。我已经尝试了所有其他答案,这些答案在堆栈溢出中给出了这个与SocketTimeoutException相关的问题,但仍然得到相同的错误。有人可以帮帮我吗?

1 个答案:

答案 0 :(得分:0)

不要使用不推荐使用的AndroidHttpTransport。而不是这个用途

HttpTransportSE httpTransportSE=new HttpTransportSE(URL)

更新:

https://www.yireo.com/tutorials/magebridge/administration/596-step-by-step-create-a-magento-api-user

检查此链接并创建这些凭据并在您的代码中使用它。之后你的问题就会解决......

快乐编码