質問

Im trying to connect to a server and than receive some data back in Json format. Here is my java code:

HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet("https://my.server.com/validate/" + data);
request.setHeader("Accept", "application/json");
request.setHeader("X-AuthToken","my authorisation code");
HttpResponse response = client.execute(request);

I also have

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

as a child of manifest (not application) in my manifest.xml

When I try to open the url in browser, I get the correct page but I dont get any data since it misses the authentication. I also have a good connection.

I've been trying to fix this for a few hours now, but I still get IOException at the line with client.execute(request)

java.net.UnknownHostException: my.server.com

Any ideas? :) Thanks!

役に立ちましたか?

解決

Seems like you're missing uses-?

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

<permission> is used to declare a new permission. Docs

他のヒント

Sorry if I'm missing something, but is my.server.com really a valid host? Did you forget to plug in the actual host?

Besides the answers here, here are a few aditional suggestions

  1. Try going to to URL in a browser
  2. Check to make sure you have an internet connection on your device by using the browser
  3. Try cleaning the project and trying again (this has done the trick for me several times) (Project -> Clean)
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top