Created
May 31, 2016 23:02
-
-
Save rms1000watt/8e4fc62a5ef0715388bc83438838c49c to your computer and use it in GitHub Desktop.
Send HTTP Request on Android
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.util.Log; | |
import java.io.BufferedInputStream; | |
import java.io.BufferedReader; | |
import java.io.InputStream; | |
import java.io.InputStreamReader; | |
import java.net.HttpURLConnection; | |
import java.net.URL; | |
private void sendHTTPRequest() { | |
try { | |
String data = ""; | |
String webPage = ""; | |
URL url = new URL("http://www.google.com/"); | |
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); | |
InputStream in = new BufferedInputStream(urlConnection.getInputStream()); | |
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8")); | |
while ((data = reader.readLine()) != null) { | |
webPage += data + "\n"; | |
} | |
Log.i("WebPage", webPage); | |
urlConnection.disconnect(); | |
} | |
catch (Exception e) { | |
Log.e("URL", e.toString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment