Reputation: 373
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?
Upvotes: 0
Views: 549
Reputation: 105133
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.
Upvotes: 1