2011-08-04 63 views
0

我有一個bugzilla服務器,我試圖通過其餘api訪問。我想通過REST遠程更新數據庫。 我出現以下情況例外,當我嘗試運行我的代碼:無法通過休息api更新webservice的遠程數據庫

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線拋出異常 任何想法爲什麼發生這種情況?

回答

0

您是否將Internet權限添加到清單中?從Android developers site

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

Thanks greg你是一個救星! – DaTaBomB