Thomas added Beispiel_fr_das_Folgen_einer__.tex  almost 8 years ago

Commit id: 8526e4e8b4b96657dcbd02895b4918e61d6455d7

deletions | additions      

         

Beispiel fr das Folgen einer Weiterleitung:  \begin{lstlisting}  URL url = new URL("http://php.net/existiertnicht");  HttpURLConnection con;  while (true) {  con = (HttpURLConnection) url.openConnection();  con.setInstanceFollowRedirects(false);  switch (con.getResponseCode()) {  case HttpURLConnection.HTTP_MOVED_PERM:  case HttpURLConnection.HTTP_MOVED_TEMP:  String next = con.getHeaderField("Location");  url = new URL(url, next);  continue;  }  break;  }  // redirects to  // http://php.net/manual-lookup.php?pattern=existiertnicht&lang=en&scope=404quickref  \end{lstlisting}  Wenn die URL in der Variable \texttt{next} mit \texttt{https://} anfngt, muss die   Klasse \texttt{HttpsURLConnection} verwendet werden.