无法通过rest api更新webservice的远程数据库
我有一个 bugzilla 服务器,我试图通过其余 api 访问它。我想通过REST远程更新数据库。 当我尝试运行我的代码时,出现以下异常:
W/DB ( 277): java.net.SocketException: Permission denied
W/DB ( 277): at org.apache.harmony.luni.platform.OSNetworkSystem.createStreamSocketImpl(Native Method)
W/DB ( 277): at org.apache.harmony.luni.platform.OSNetworkSystem.createStreamSocket(OSNetworkSystem.java:186)
W/DB ( 277): at org.apache.harmony.luni.net.PlainSocketImpl.create(PlainSocketImpl.java:265)
W/DB ( 277): at java.net.Socket.checkClosedAndCreate(Socket.java:873)
W/DB ( 277): at java.net.Socket.connect(Socket.java:1020)
W/DB ( 277): at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
W/DB ( 277): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:143)
W/DB ( 277): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
W/DB ( 277): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
W/DB ( 277): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:348)
W/DB ( 277): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
W/DB ( 277): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
W/DB ( 277): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
W/DB ( 277): at com.geek.myzilla.RestClient.myputter(RestClient.java:269)
W/DB ( 277): at com.geek.myzilla.MyZillaActivity.onCreate(MyZillaActivity.java:59)
W/DB ( 277): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
W/DB ( 277): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
RestClient.myputter 函数看起来像这样:
public static String myputter(String... params)
{
String url = params[0];
String jsonBody = params[1];
DefaultHttpClient client = new DefaultHttpClient();
HttpPut putRequest = new HttpPut(url);
try {
StringEntity se = new StringEntity(jsonBody);
se.setContentType("text/json");
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
putRequest.setEntity(se);
putRequest.addHeader("Content-Type", "application/json");
putRequest.setEntity(se);
putRequest.setHeader("Accept", "application/json");
putRequest.setHeader("Content-Type", "application/json");
HttpResponse response = client.execute(putRequest);
int status_code=response.getStatusLine().getStatusCode();
client.execute 行抛出异常 有什么想法为什么会发生这种情况吗?
I have a bugzilla server which i am trying to access through the rest api . I want to update the database remotely through REST.
I get the following exception when i try to run my code:
W/DB ( 277): java.net.SocketException: Permission denied
W/DB ( 277): at org.apache.harmony.luni.platform.OSNetworkSystem.createStreamSocketImpl(Native Method)
W/DB ( 277): at org.apache.harmony.luni.platform.OSNetworkSystem.createStreamSocket(OSNetworkSystem.java:186)
W/DB ( 277): at org.apache.harmony.luni.net.PlainSocketImpl.create(PlainSocketImpl.java:265)
W/DB ( 277): at java.net.Socket.checkClosedAndCreate(Socket.java:873)
W/DB ( 277): at java.net.Socket.connect(Socket.java:1020)
W/DB ( 277): at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
W/DB ( 277): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:143)
W/DB ( 277): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
W/DB ( 277): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
W/DB ( 277): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:348)
W/DB ( 277): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
W/DB ( 277): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
W/DB ( 277): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
W/DB ( 277): at com.geek.myzilla.RestClient.myputter(RestClient.java:269)
W/DB ( 277): at com.geek.myzilla.MyZillaActivity.onCreate(MyZillaActivity.java:59)
W/DB ( 277): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
W/DB ( 277): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
The RestClient.myputter function looks something like this:
public static String myputter(String... params)
{
String url = params[0];
String jsonBody = params[1];
DefaultHttpClient client = new DefaultHttpClient();
HttpPut putRequest = new HttpPut(url);
try {
StringEntity se = new StringEntity(jsonBody);
se.setContentType("text/json");
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
putRequest.setEntity(se);
putRequest.addHeader("Content-Type", "application/json");
putRequest.setEntity(se);
putRequest.setHeader("Accept", "application/json");
putRequest.setHeader("Content-Type", "application/json");
HttpResponse response = client.execute(putRequest);
int status_code=response.getStatusLine().getStatusCode();
The client.execute line is throwing the exception
Any ideas why this is happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否在清单中添加了互联网权限?来自 Android 开发者网站。
Did you add the Internet permission to the manifest? From Android developers site.