2011-10-11 88 views
0

我只需要通過普通的HTTP POST發送請求到webservice來獲得response.I在身體上傳遞了所需的參數。當我運行它時,我得到了「無法處理消息,因爲內容類型'text/json'不是期望的類型'application/soap + msbin1'。「錯誤。當我對此進行研究時,由於「Web服務需要請求具有特定的Content-Type,即」application/soap + msbin1「。當我替換預期的內容類型時,我得到了錯誤的請求錯誤。唐諾如何從恢復應用程序/肥皂+ msbin1在android

我的代碼: ...

DefaultHttpClient httpClient = new DefaultHttpClient(); 
    ResponseHandler <String> resonseHandler = new BasicResponseHandler(); 
    HttpPost postMethod = new HttpPost("My URL"); 
    postMethod.setHeader("Content-Type", "text/json"); 
    postMethod.setHeader("Cache-Control", "no-cache"); 



    JSONObject json = new JSONObject(); 
    json.put("userName", "My Username"); 
    json.put("password", "My Password"); 
    json.put("isPersistent",false); 


    postMethod.setEntity(new ByteArrayEntity(json.toString().getBytes("UTF8"))); 
    HttpResponse response = httpClient.execute(postMethod); 

...

回答

0

它看起來像你試圖調用WCF SOAP服務,服務需要正確的SOAP通信。 (=沒有JSON),而且它使用SOAP消息的MS二進制消息編碼(這是內容類型描述的)不可互操作,所以我懷疑你無線就可以在Android設備上使用它(除非你找到Java/Android編碼的實現)。

0
HttpPost request = new HttpPost(url);  
StringEntity entity = new StringEntity(json.toString()); 
          entity.setContentType("application/json;charset=UTF-8");       entity.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,"application/json;charset=UTF-8")); 
          request.setHeader("Accept", "application/json"); 
          request.setEntity(entity); 

try{ 
DefaultHttpClient httpClient = new DefaultHttpClient(); 
    response = httpClient.execute(request); 
} 

嘗試使用類似這樣的東西。它爲我工作。

謝謝。 N_JOY。