2017-01-12 3 views
0

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(); 
     } 
    } 
+1

Mögliches Duplikat (http://stackoverflow.com/questions/7648872/can-i-override-the-host -header-where-using-javas-httpurlconnection-Klasse) –

+0

In der Tat. Ich habe 'System.setProperty ("sun.net.http.allowRestrictedHeaders", "true") auf 'Application.onCreate()' gesetzt und es funktioniert nicht. – HelderMPinhal

Antwort