2016-09-12 11 views
0

私はいくつかの異なる例を見てきました。私の目標は、私の要求にJSONのコンテンツタイプを追加することです。ヘッダがなければ、私の要求はエラーはありません:soap webserviceに「content-type」ヘッダーを追加する方法

public void calculate() { 
     String SOAP_ACTION = "http://----/--"; 
     String METHOD_NAME = "----"; 
     String NAMESPACE = "http://-----/"; 
     String URL = "http://----/---/----.asmx"; 
     try { 
      // Creating a new empty SOAP message object 

      SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME); 
      Request.addProperty("username", "***"); 
      Request.addProperty("password", "****"); 
      SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
      soapEnvelope.dotNet = true; 
      soapEnvelope.setOutputSoapObject(Request); 

      HttpTransportSE transport = new HttpTransportSE(URL); 


      transport.call(SOAP_ACTION, soapEnvelope); 

      resultString = (SoapPrimitive) soapEnvelope.getResponse(); 

      Log.i(TAG, "Result Celsius: " + resultString); 
     } catch (Exception ex) { 
      Log.e(TAG, "Error: " + ex.getMessage()); 
     } 
    } 

答えて

1

// Create a of HeaderProperty 
List<HeaderProperty> headerList = new ArrayList<HeaderProperty>(); 
// Add Content-Type to the list 
headerList.add(new HeaderProperty("Content-Type", "application/json; charset=UTF-8")); 

// Pass this list as 3rd argument to call method 
transport.call(SOAP_ACTION, soapEnvelope, headerList); 
、これを試してみてください
関連する問題