List of usage examples for java.net HttpURLConnection HTTP_MOVED_TEMP
int HTTP_MOVED_TEMP
To view the source code for java.net HttpURLConnection HTTP_MOVED_TEMP.
Click Source Link
From source file:study.tdcc.act.MainCalendar.java
/** * XML?????/* w w w . java 2 s . c o m*/ * * @param strUrl * @param strXml * @param strMethod (PUT,DELETE) * @return InputStream ???InputStream */ public InputStream httpPostXml(String strUrl, String strXml, String strMethod) { Log.d("DEBUG", "MainCalendar httpPostXml Start"); blHttpSucceeded = false; try { while (strUrl != null) { URL urlObj = new URL(strUrl); //URL????? HttpURLConnection httpURLCObj = (HttpURLConnection) urlObj.openConnection(); //?POST? httpURLCObj.setRequestMethod("POST"); //GData-Version? httpURLCObj.setRequestProperty(GDATA_VERSION_TAG, GDATA_VERSION); if (strMethod != null) { //POST??????If-Match:*?X-HTTP-Method-Override httpURLCObj.setRequestProperty("If-Match", "*"); httpURLCObj.setRequestProperty("X-HTTP-Method-Override", strMethod); } // httpURLCObj.setDoOutput(true); //Content-Type??XML httpURLCObj.setRequestProperty("Content-Type", CONTENT_TYPE_AA); // httpURLCObj.setUseCaches(false); //OutputStreamWriter??XML?? OutputStreamWriter outputStreamWriter = new OutputStreamWriter(httpURLCObj.getOutputStream(), "UTF-8"); outputStreamWriter.write(strXml); outputStreamWriter.close(); //HTTP?? intResponseCode = 0; intResponseCode = httpURLCObj.getResponseCode(); strUrl = null; Log.d("DEBUG", "MainCalendar httpPostXml HttpResponseCode : " + intResponseCode); if (intResponseCode == HttpURLConnection.HTTP_OK || intResponseCode == HttpURLConnection.HTTP_CREATED) { //??OK???CREATED????? blHttpSucceeded = true; Log.d("DEBUG", "MainCalendar httpPostXml End(1)"); //?InputStream?? return httpURLCObj.getInputStream(); } else if (intResponseCode == HttpURLConnection.HTTP_MOVED_TEMP) { //??MOVED_TEMP????????? //?Location????URL????(?while? Map<String, List<String>> mResponseHeaders = httpURLCObj.getHeaderFields(); if (mResponseHeaders.containsKey("Location")) { strUrl = mResponseHeaders.get("Location").get(0); } else if (mResponseHeaders.containsKey("location")) { strUrl = mResponseHeaders.get("location").get(0); } } else { //??OK???CREATED???MOVED_TEMP?? blHttpSucceeded = false; Log.d("DEBUG", "MainCalendar httpPostXml End(2) ??OK,CREATED,MOVED_TEMP??"); } } } catch (Exception e) { Log.e("ERROR", "MainCalendar httpPostXml ERROR", e); } Log.d("DEBUG", "MainCalendar httpPostXml End(3)"); return null; }
From source file:org.kuali.test.utils.Utils.java
/** * * @param status// ww w .j av a 2 s . com * @return */ public static boolean isHttpRedirect(int status) { return ((status == HttpURLConnection.HTTP_MOVED_TEMP) || (status == HttpURLConnection.HTTP_MOVED_PERM) || (status == HttpURLConnection.HTTP_SEE_OTHER)); }
From source file:uk.ac.vfb.geppetto.VFBProcessTermInfo.java
/** * @param urlString//from w w w.jav a 2 s.c o m */ private String checkURL(String urlString) { try { urlString = urlString.replace("https://", "http://").replace(":5000", ""); urlString = urlString.replace("//virtualflybrain.org", "//www.virtualflybrain.org"); URL url = new URL(urlString); HttpURLConnection huc = (HttpURLConnection) url.openConnection(); huc.setRequestMethod("HEAD"); huc.setInstanceFollowRedirects(true); int response = huc.getResponseCode(); if (response == HttpURLConnection.HTTP_OK) { return urlString; } else if (response == HttpURLConnection.HTTP_MOVED_TEMP || response == HttpURLConnection.HTTP_MOVED_PERM) { return checkURL(huc.getHeaderField("Location")); } return null; } catch (Exception e) { System.out.println("Error checking url (" + urlString + ") " + e.toString()); return null; } }