搜尋此網誌

2013年10月8日 星期二

【Java】HTTP response code 505解決辦法

如題
URL url = new URL(urlstring.trim());                        
urlConnection = (HttpURLConnection) url.openConnection();
int response = urlConnection.getResponseCode();

解決辦法
需對url的parameter先作encode
String urlString = "http://test.com?param1=" + URLEncoder.encode(value1, "UTF-8") + "&param2=" + URLEncoder.encode(value2, "UTF-8") ;

URL url = new URL(urlstring.trim());                        
urlConnection = (HttpURLConnection) url.openConnection();
int response = urlConnection.getResponseCode();
參考:

  1. http://stackoverflow.com/questions/13252814/getting-505-responce-from-server
  2. http://stackoverflow.com/questions/3625659/java-io-ioexception-server-returns-http-response-code-505

沒有留言: