2011-10-05 50 views
0

我想調用一個soap webservice,如下所示。我添加了互聯網權限清單文件,但我仍然得到異常(SocketException:權限被拒絕)。儘管爲清單文件添加了Internet權限,但爲什麼仍然收到SocketException PermissionDenied異常?

class CallWebService extends AsyncTask<String, Void, String> { 

    @Override 
    protected String doInBackground(String... parameters) { 
     final DefaultHttpClient httpClient=new DefaultHttpClient(); 
     // request parameters 
     HttpParams params = httpClient.getParams(); 
     HttpConnectionParams.setConnectionTimeout(params, 10000); 
     HttpConnectionParams.setSoTimeout(params, 15000); 
     // set parameter 
     HttpProtocolParams.setUseExpectContinue(httpClient.getParams(), true); 

     // POST the envelope 
     HttpPost httppost = new HttpPost(parameters[0]); 
     // add headers 
     httppost.setHeader("soapaction", parameters[1]); 
     httppost.setHeader("Content-Type", "text/xml; charset=utf-8"); 

     String responseString=""; 
     try { 

      // the entity holds the request 
      HttpEntity entity = new StringEntity(parameters[2]); 
      httppost.setEntity(entity); 

      // Response handler 
      ResponseHandler<String> rh=new BasicResponseHandler(); 

      /*{ 
      // invoked when client receives response 
      public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException { 

      // get response entity 
      HttpEntity entity = response.getEntity(); 

      // read the response as byte array 
        StringBuffer out = new StringBuffer(); 
        byte[] b = EntityUtils.toByteArray(entity); 

        // write the response byte array to a string buffer 
        out.append(new String(b, 0, b.length));   
        return out.toString(); 
      } 
      }; 
      */ 
      responseString=httpClient.execute(httppost, rh); 

     } 
     catch (Exception e) { 
      Log.v("exception", e.toString()); 
     } 

     // close the connection 
     httpClient.getConnectionManager().shutdown(); 
     return responseString; 
    } 
} 
+0

也請發表您的清單文件 – Caner

回答

2

您是否已將互聯網權限置於清單頂部(應用程序)級別(如下所示)。沒有錯誤報告,如果你把它低了下去,但你不會得到訪問互聯網......

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package=... 
    android:versionCode="1" 
    android:versionName="1.0"> 
    <application 
     ... 
    </application> 
    <uses-sdk android:minSdkVersion="7" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 
</manifest> 
+0

我錯過了它塊之間留英寸我把它放在塊之外,然後開始運行。謝謝Torid。 –

相關問題