开发者

Despite adding internet permission to manifest file why am I still getting SocketException PermissionDenied exception?

开发者 https://www.devze.com 2023-04-10 18:52 出处:网络
I want to call a soap webservice as below. I added internet permission to manifest file but i am still getting the exception (SocketException: permission denied).

I want to call a soap webservice as below. I added internet permission to manifest file but i am still getting the exception (SocketException: permission denied).

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(http开发者_高级运维Client.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;
    } 
}


Have you put the internet permission at the top (application) level of your manifest (as below). No errors are reported if you put it lower down, but you will not get access to the internet...

<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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号