Code example for HttpURLConnection

Methods: addRequestProperty, connect, disconnect, getInputStream, setConnectTimeout, setDoInput, setReadTimeout, setRequestMethod

0
		         String endp = URLEncoder.encode(end, "UTF-8");
		          
		         URL url = new URL(
		        		 "http://cakewalk.heroku.com/paths/search_path_android?m[start]="+start+"&m[finish]=" + endp);
		         con = (HttpURLConnection) url.openConnection();
		         con.setReadTimeout(10000 /* milliseconds */);
		         con.setConnectTimeout(15000 /* milliseconds */);
		         con.setRequestMethod("GET");
		         con.addRequestProperty("Referer",
		               "http://www.pragprog.com/titles/eband3/hello-android"); 
		         con.setDoInput(true);
 
		         // Start the query 
		         con.connect();
 
		         // Check if task has been interrupted 
		   //      if (Thread.interrupted()) 
		   //         throw new InterruptedException(); 
 
		         // Read results from the query 
		         BufferedReader reader = new BufferedReader(
		         new InputStreamReader(con.getInputStream(), "UTF-8"));
		         String payload = reader.readLine();
		         reader.close();
		          
		          
 
		         result = payload;
		         // Check if task has been interrupted 
		         if (Thread.interrupted())
		            throw new InterruptedException();
 
		      } catch (IOException e) {
		         return result;
		      } catch (InterruptedException e) {
		         result = "@string/translation_interrupted";
		      } finally { 
		         if (con != null) {
		            con.disconnect();
		         } 
		      } 
		       
		      return result;