无法通过rest api更新webservice的远程数据库

发布于 2024-11-27 16:55:54 字数 2792 浏览 1 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

荒芜了季节 2024-12-04 16:55:54

您是否在清单中添加了互联网权限?来自 Android 开发者网站

    <uses-permission android:name="android.permission.INTERNET" /> 

Did you add the Internet permission to the manifest? From Android developers site.

    <uses-permission android:name="android.permission.INTERNET" /> 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文