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();
}
}}}

New Topic/Question
This topic is locked


MultiQuote





|