使用 ksoap2 从 magento 网络服务获取会话 ID 时出错

Error in getting session id from magento web service using 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 相关问题,我已经尝试了堆栈溢出中给出的所有其他答案,但仍然遇到相同的错误。谁能帮帮我?

不要使用已弃用的 AndroidHttpTransport。而不是这个使用

HttpTransportSE httpTransportSE=new HttpTransportSE(URL)

已更新:

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

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

编码愉快