无法通过rest api更新Web服务的远程数据库

时间:2011-08-04 15:16:45

标签: android json rest bugzilla

我有一个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行抛出异常 任何想法为什么会发生这种情况?

1 个答案:

答案 0 :(得分:0)

您是否在清单中添加了Internet权限?来自Android developers site

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