2016-07-28 20 views
4

サーバにリクエストを送信するときにKSOAP2を使用していて、java.io.IOExceptionが発生しました:HTTPリクエストが失敗しました。 httpTransport.call(SOAP_ACTION, envelope)という行がありますが、サーバーは動作しますが、私はSoapUIを使用してチェックしています。何が問題なの?java.io.IOException:HTTPリクエストが失敗しました。HTTPステータス:500(ksoap2)

public class SOAPClient 
{ 
    private static final int TIMEOUT_SOCKET = 180000; 

    public static SoapObject get(Context context, String methodName, ArrayList<Pair<String, ?>> args) throws Exception 
    { 
     final String URL = PrefHelper.getSOAPUrl(context); 
     final String NAMESPACE = PrefHelper.getSOAPNamespace(context); 
     final String SOAP_ACTION = methodName; //NAMESPACE + "#" + "mapx" + ":" + methodName; 

     SoapObjectEve request = new SoapObjectEve(NAMESPACE, methodName); 

     if (args != null) { 
      for (Pair<String, ?> arg : args) { 
       if (arg.first != null) { 
        request.addProperty(arg.first, arg.second); 
       } 
      } 
     } 

     SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
     new MarshalBase64().register(envelope); 
     envelope.setOutputSoapObject(request); 

     envelope.implicitTypes = true; 

     HttpTransportSE httpTransport = new HttpTransportSE(URL, TIMEOUT_SOCKET); 
     httpTransport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); 
     try 
     { 
      httpTransport.call(SOAP_ACTION, envelope); 
      AppLog.e(httpTransport.requestDump+"requestDump"); 


     } 
     catch (ConnectTimeoutException e) { 
      AppLog.e(e.getMessage()); 
      throw new Exception(context.getString(R.string.node_unavailable)); 
     } 
     catch (SocketTimeoutException e) { 
      AppLog.e(e.getMessage()); 
      throw new Exception(context.getString(R.string.timeout)); 
     } 
     catch (Exception e) { 
      e.printStackTrace(); 
      AppLog.e(e.getMessage()); 

      AppLog.e(httpTransport.requestDump+"requestDump"); 
      throw new Exception(context.getString(R.string.warning_error_get_data) + e.getMessage() == null ? "" : " " + e.getMessage()); 
     } 

     AppLog.i(httpTransport.requestDump+"requestDump"); 

     SoapObject soapObj = null; 

     try { 
      soapObj = (SoapObject) envelope.getResponse(); 
     } 
     catch (Exception e) { 

      String response = ((SoapPrimitive) envelope.getResponse()).toString(); 
      boolean res = Boolean.valueOf(response); 

      soapObj = new SoapObject(); 
      soapObj.addProperty("response", res); 
      soapObj.addProperty("msg", ""); 
      soapObj.addProperty("data", null); 

     } 
     AppLog.e(httpTransport.responseDump+"responseDump"); 
     return soapObj; 
    } 
} 
+0

'500'、あなたがマニフェストにインターネットアクセス権を持っていることを確認し、このコードを試してみてくださいは、内部サーバーエラーが発生したことを意味します。サーバーログをチェックして、何がうまくいかないかを確認します。 –

+0

@KNeerajLalサーバーerrors.logにエラーはありません。 –

+0

リクエストダンプはどのように見えますか? wsdlが指定するのと同じですか? –

答えて

2

あなたNAMESPACEMETHODNAMEWSDLSOAP_ACTIONが正しいことを確認してください。

private static final String NAMESPACE = "http://www.kltro.com"; 
private static final String METHODNAME = "getUser"; 
private static final String WSDL = "http://ap.kashkan.org:55555/tro/ws/kltro"; 
private static final String SOAP_ACTION = NAMESPACE + "#kltro:" + METHODNAME ; 

private static String TAG = "soap"; 

public static String callWebservice() { 
    String responseDump = ""; 
    try { 
     SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 

     SoapObject request = new SoapObject(NAMESPACE, METHODNAME); 
     request.addProperty("login", login); 
     request.addProperty("pass", password); 
     request.addProperty("androidID", androidID); 
     request.addProperty("ver", version); 

     envelope.bodyOut = request; 
     HttpTransportSE transport = new HttpTransportSE(WSDL); 
     transport.debug = true; 
     try { 
      transport.call(SOAP_ACTION, envelope); 
      String requestDump = transport.requestDump; 
      responseDump = transport.responseDump; 
      Log.e(TAG, requestDump); 
      Log.e(TAG, responseDump); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 

    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
    return responseDump; 
} 

また

<uses-permission android:name="android.permission.INTERNET" /> 
+1

恐ろしく、それは動作します!どうもありがとう! –

関連する問題