Back to project page android-udoo-rover.
The source code is released under:
Copyright (c) 2014, Emanuele Palazzetti and contributors All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the followin...
If you think the Android project android-udoo-rover listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package me.palazzetti.adkrover.utils; /*www .ja v a 2 s . c o m*/ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.ProtocolException; import java.net.URL; /** * Fast GET/POST connector built on top of HttpURLConnection. * It is *NOT* suitable for generic purpose but it's customized for this project. */ public class UrlConnector { private HttpURLConnection mConnector; public UrlConnector(String encodedUrl) throws MalformedURLException, IOException { URL url = new URL(encodedUrl); mConnector = (HttpURLConnection) url.openConnection(); mConnector.setReadTimeout(10000); mConnector.setConnectTimeout(15000); mConnector.setUseCaches(false); } public void addHeader(String header, String content) { mConnector.setRequestProperty(header, content); } public int get() throws ProtocolException, IOException { mConnector.setRequestMethod("GET"); mConnector.setDoInput(true); return mConnector.getResponseCode(); } public String getResponse() throws IOException { BufferedReader readerBuffer = new BufferedReader(new InputStreamReader(mConnector.getInputStream())); StringBuilder response = new StringBuilder(); String line; while ((line = readerBuffer.readLine()) != null) { response.append(line); } return response.toString(); } public void disconnect() { mConnector.disconnect(); } }