my code stock.com

Snippet options

Download: Download snippet as ourhttp.java.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

package com.example.bluwif;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URI;
import java.net.URISyntaxException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;

import android.app.Activity;
import android.os.StrictMode;
import android.util.Log;
import android.view.View;



public class ourHTTP extends Activity {
	

	public String getWebPage(String adress)
	{
	HttpClient httpClient = new DefaultHttpClient();
		HttpGet httpGet = new HttpGet();
		
		InputStream inputStream = null;
		String response = null;
		
		
		try{
			URI uri = new URI(adress);
			httpGet.setURI(uri);
			
			HttpResponse httpResponse = httpClient.execute(httpGet);

			
			inputStream = httpResponse.getEntity().getContent();
			Reader reader = new InputStreamReader(inputStream, "UTF-8");
			int inChar;
			StringBuffer stringBuffer = new StringBuffer();
			
			while((inChar = reader.read()) != -1){
				
				stringBuffer.append((char)inChar);
			}
			
			response = stringBuffer.toString();
			
		}catch(ClientProtocolException e)
		{
			Log.e(adress, "error");
		}catch(IOException e)
		{
			Log.e(response, "error");
			//
		}catch(URISyntaxException e)
		{
			Log.e(response, "error"); 
		}
		
		return response;
		}
	
	public void sendToServer(String temp_send)
	{
		StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
			     .detectAll()
			     .penaltyLog()
			     .build();
			 StrictMode.setThreadPolicy(policy);
		
		
	
		String method = "register";
		
		
		BackgroundTask backgroundTask = new BackgroundTask(this);
		backgroundTask.execute(method, temp_send);
		finish();
		
	}




}

Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.