2011-09-25 1 views
1

나는이 간단한 코드를 가지고있어 웹 서비스를 얻는다.UnknownHostException (webservice http-get)

String URL = "http://services.sapo.pt/EPG/GetChannelList"; 
String result = ""; 
final String tag = "Data received: "; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    final Button btnSearch = (Button)findViewById(R.id.btnSearch); 
    btnSearch.setOnClickListener(new Button.OnClickListener(){ 
     public void onClick(View v) { 
      callWebService(); 
     } 
    }); 

} // end onCreate() 

public void callWebService(){ 
    HttpClient httpclient = new DefaultHttpClient(); 
    HttpGet request = new HttpGet(URL); 
    ResponseHandler<String> handler = new BasicResponseHandler(); 

    try { 
     result = httpclient.execute(request, handler); 
    } catch (ClientProtocolException e) { 
     e.printStackTrace(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 

    httpclient.getConnectionManager().shutdown(); 
    Log.i(tag, result); 
} 

이 이미있는 경우 내 매니페스트

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

<application android:icon="@drawable/icon" android:label="@string/app_name"> 
    <activity android:name=".AndroidApp" 
       android:label="@string/app_name"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
</application> 
+0

URL이 작동하는지 확인하려면 브라우저를 먼저 사용하십시오. –

+0

예 ... 브라우저에 연결되어 있지 않을 수도 있습니다. –

+0

url이 작동하고 브라우저를 확인했는데 인터넷이 연결되어 있습니다. v1.6으로 제작되었습니다. 나는 웹을 검색하고 그것이 매니 페스트에 대한 허가를 추가하는 것을 가리키고 있지만 나는 이미 그렇게했다. – bruno

답변

1

해결책을 찾았습니다. 나는 태그를 추가 매니페스트에 GUI를 사용하여 인터넷 권한을 퍼트

< 권한 안드로이드 : 이름 "android.permission.INTERNET은"/

다음

손으로, 나는이 올바른 태그를 퍼트> :

< 사용 - 권한 안드로이드 : 이름 = "android.permission.INTERNET은"/>

다른 태그이며이 일

. GUI가 실패합니다.

0

확실하지의 일부입니다 : 그것은 연결하지 못할 어떤 이유 코드를 로그 UnknownHostException의

이있는 오류입니다 제공 이것을 확인했는데 프록시 또는 방화벽을 사용하고 있는지 확인하십시오. 다음은 way to configure the HttpClient for a proxy이고 공식은 apache documentation입니다.

+0

이 네트워크에서 프록시를 사용하지 않습니다. 저는 다른 웹 서비스를 다른 응용 프로그램과 함께 사용하고 있습니다. 이건 웬일인지 아닌데. – bruno