Http example

Page 1 of 1

1 Replies - 1018 Views - Last Post: 18 October 2011 - 08:19 AM

#1 ashwinikm   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 03-October 11

Http example

Posted 18 October 2011 - 05:52 AM

helo,

Me working on the small http sample.
JAVA application will connect to www.google.com
- JAVA application will donwload google page (without pictures) on File System,
in "output.html" file.
main.cfg is required to store the right GPRS network parameters.

this below pgm works on pc but not on the hardware which has gsm antenna and sim card facilty.
where i think there is prob with the gprs network parameters.
web.APN=
web.username=
web.password=

so me using the idea sim where i store in apn imis and other two parameters as null.
so pls help out what might be the problem



import java.io.*;

import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

/*
 * 
 * 
 * Simple application that open the  http://www.google.com web page
 * and print its content in a file output.html 
 * 
 * as a pre-requisite don't forget to add main.cfg into the  file system
 * with your APN configuration   
 *  
 */ 

public class Main {

	public static void main(String[] args) {

		System.out.println("------------------------------------");
		System.out.println("HTTP Example");
		System.out.println("------------------------------------");


		final int BUFSIZE = 512;
		HttpURLConnection httpUrlConn = null;
		
		URL url = null;
		InputStream httpIn = null;
		BufferedReader in = null;
		FileOutputStream fileOut = null;
		String urlString = "http://www.google.com";

		try {
		
			// output file
			fileOut = new FileOutputStream( "/app/pop/out.html");
			
			// open http connection
			try {
				url = new URL(urlString);
			} catch (MalformedURLException e) {
				e.printStackTrace();
			}
			httpUrlConn = (HttpURLConnection)url.openConnection();
			//httpUrlConn.setRequestProperty("Connection", "keep-alive"); // not necessary
			httpUrlConn.setRequestProperty("Connection", ""); 
			//httpUrlConn.setRequestMethod("GET");


			// open the input stream
			httpIn = httpUrlConn.getInputStream();
			byte[] data = new byte[BUFSIZE];
			int bytesRead = 0;
			
			// transfer all data received to a file
			do {
				bytesRead = httpIn.read(data);
				System.out.println("writing data to file");
				if (bytesRead>0) fileOut.write(data, 0, bytesRead);
			} while (bytesRead > 0);

		} catch (IOException e) {
			e.printStackTrace();
		}
		
		finally {
			// close everything
			if (fileOut != null) {
				try {
					fileOut.close();
				} catch (IOException e) {
					// ignore
				}
			}

			if (in != null) {
				try {
					in.close();
				} catch (IOException e) {
					// ignore
				}
			}

			if (httpUrlConn != null) {
				httpUrlConn.disconnect();
			}
		}}}


Is This A Good Question/Topic? 0
  • +

Replies To: Http example

#2 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12800
  • View blog
  • Posts: 45,992
  • Joined: 27-December 08

Re: Http example

Posted 18 October 2011 - 08:19 AM

This violates Google's Terms of Service. You have to use one of their searching APIs to scrape search results.

Topic closed.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1