0

I tried following URL:

http://validator.w3.org/mobile/check?docAddr=mobisoft.net.pl&output=unicorn

In desktop firefox or chrome browsers and all works fine. It returns valid XML response.

After that I created Android application, which connects to W3C in order to get the validation results. Code below:

Url url = new URL("http://validator.w3.org/mobile/check?docAddr=mobisoft.net.pl&output=unicorn"); 
URLConnection connection = url.openConnection();
HttpURLConnection httpConnection = (HttpURLConnection) connection;

int responseCode = httpConnection.getResponseCode();

I always get HTTP status code 500 INTERNAL SERVER PROBLEM, despite the fact, that it works fine, while executing the same url on the desktop browsers. The same problem for other websites.

Do you have any idea, why it does not work in my Android application?

Paweł
  • 363
  • 1
  • 5
  • 13
  • Perhaps the URL is being mangled somehow by android before it's sent out to the server. Some escaping being done, perhaps? – Marc B Apr 10 '12 at 18:57
  • Have you tried making the webrequest as described here, just in case http://stackoverflow.com/questions/3505930/make-in-http-request-with-android – Graham Smith Apr 10 '12 at 18:59
  • Why are you comparing the execution of a java program on android to the result you get on a desktop browser? You're adding lots of unnecessary unknowns. Does the url work on the mobile browser? Does the program work in a normal java application on your desktop? – Voo Apr 10 '12 at 19:01
  • I tried the same URL in the Android default browser on the mobile device and it works fine. – Paweł Apr 10 '12 at 19:05
  • Well then next step try it from a normal java program on the desktop :) – Voo Apr 10 '12 at 19:07
  • I tried the same code on Java desktop application and it returns HTTP status code 200. – Paweł Apr 10 '12 at 19:12
  • @Graham Smith - using webrequest also returns HTTP 500 status code – Paweł Apr 10 '12 at 19:28
  • Interesting so we know now that there's no general problem on the phone and that the program works just. Next guess: Security problem? Make sure the right rights are set in the manifest. – Voo Apr 10 '12 at 19:51
  • I have permission: I don't think that any other permission is needed. – Paweł Apr 10 '12 at 19:59

1 Answers1

1

Try to add a HTTP "User-Agent" header, maybe that's the problem. Otherwise, I would suggest to use an existing open source Java library, which does this validation on your behalf (through W3C): rexsl-w3c

edit: Add "Accept" HTTP header with "application/soap+xml" value, will work fine.

yegor256
  • 102,010
  • 123
  • 446
  • 597