Ich muss den Host-Header für eine sehr spezifische Anfrage festlegen, und dies wird nicht berücksichtigt.HttpUrConnect gesetzt Host-Header
Ich weiß, dass dies eine eingeschränkte Kopfzeile ist, aber wie ist es möglich, es zu tun?
Hier ist, was ich versuche.
HttpURLConnection urlConnection = null;
try {
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setConnectTimeout(10000);
urlConnection.setRequestProperty("Host", "test.com");
urlConnection.setRequestMethod("GET");
int responseCode = urlConnection.getResponseCode();
Log.d(TAG, String.format("response code: %d", responseCode));
} catch (IOException e) {
} finally {
if (urlConnection != null) {
urlConnection.disconnect();
}
}
Mögliches Duplikat (http://stackoverflow.com/questions/7648872/can-i-override-the-host -header-where-using-javas-httpurlconnection-Klasse) –
In der Tat. Ich habe 'System.setProperty ("sun.net.http.allowRestrictedHeaders", "true") auf 'Application.onCreate()' gesetzt und es funktioniert nicht. – HelderMPinhal