1

I have this simple code, that makes a get to a webservice. For some reason it cant connect and gives the error in the log unknownHostException

This is the code:

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);
}

This is part of my manifest

<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>
5
  • check if your url is working, may be with browser first. Commented Sep 25, 2011 at 9:23
  • yeah...i think you may not have connectivity in your browser Commented Sep 25, 2011 at 9:26
  • url is working, checked browser and it has got internet. It was created with v1.6. I search the web and it all point to add permission to manifest but i already did that. Commented Sep 25, 2011 at 9:29
  • can you plz post the exception trace ? Commented Sep 25, 2011 at 13:01
  • I made a new piece of code to connect to the webservice and it worked, but still couldn´t figured what was wrong with this one. Commented Sep 27, 2011 at 13:55

2 Answers 2

1

I found the solution. I putted the internet permission using the GUI in manifest which added the tag

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

Then by hand, i putted the correct tag that is:

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

which is a different tag and it worked. GUI fail.

Sign up to request clarification or add additional context in comments.

Comments

0

Not sure if you have already checked this, but please check if you are behind a proxy or firewall. Here is a way to configure the HttpClient for a proxy and official apache documentation.

1 Comment

No proxy used in this network, i´m consuming other webservices with other apps and they work. This one for some reason is not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.