尽管向清单文件添加了互联网权限,为什么我仍然收到 SocketException PermissionDenied 异常?
我想调用一个肥皂网络服务,如下所示。我向清单文件添加了互联网权限,但仍然收到异常(SocketException:权限被拒绝)。
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;
}
}
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(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;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否将互联网权限置于清单的顶层(应用程序)(如下所示)。如果你把它放低一点,不会报告错误,但你将无法访问互联网......
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...