2014-01-22 68 views
1

Image to post request using 的Android HttpPost不帶參數的名字

我使用POST方法多次在過去,但得到這個怪異的網絡服務。它在Chrome擴展上工作正常,但我無法使用android獲得此響應。請在代碼中如果它丟失了

這裏是代碼我使用

   HttpParams param = new BasicHttpParams(); 
      param.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); 
      HttpClient httpclient = new DefaultHttpClient(param); 
      HttpPost httppost = new HttpPost(url); 
      Utils.showLogs(MyConstants.TAG, "ApplicationURL: " + url); 

      httppost.setHeader("Content-type", contentType); 
      HttpConnectionParams.setConnectionTimeout(param, MyConstants.WEBSERVICE_TIMEOUT); 
      HttpConnectionParams.setSoTimeout(param, MyConstants.WEBSERVICE_TIMEOUT); 

      String response = null; 
      try { 
       if (jsonObject == null) { 
        StringEntity entity = new StringEntity(json, HTTP.UTF_8); 
        httppost.setEntity(entity); 
       } else { 
        StringEntity stringEntity = new StringEntity(jsonObject.toString()); 
        httppost.setEntity(stringEntity); 

       } 
       // Execute HTTP Post Request 
       HttpResponse httpResponse = httpclient.execute(httppost); 
       final int statusCode = httpResponse.getStatusLine().getStatusCode(); 
       if (statusCode != HttpStatus.SC_OK) { 
        return MyConstants.SERVER_NOT_RESPONDING; 
       } 
       HttpEntity httpEntity = httpResponse.getEntity(); 
       response = EntityUtils.toString(httpEntity); 

感謝

+0

請解釋更多關於這個問題,你會收到一個錯誤? logcat的?如果你調試的代碼輸入if(statusCode!= HttpStatus.SC_OK)? –

+0

我收到回覆,但它的{「消息」:「發生了錯誤。」}。它的服務器錯誤500. – Jan

+0

範你訪問服務器日誌或寫一些日誌來檢查這個錯誤的主要細節? –

回答

0

你在AndroidManifest.xml添加<uses-permission android:name="android.permission.INTERNET" />補充?

如果沒有,添加這應該是好的!