M
Marko
I'm having big trouble with a small J2ME app. In a nutshell.. MIDlet
just doesn't want to pass HTTP requests through a proxy.
Needless to say I've set up correctly all proxy's parameters in the
Toolkit's preferences. As a matter of fact, I'm using the same proxy
to post this message.
I'm using standard J2ME code for sending HTTP GET and POST requests.
Nothing fancy. Also, my proxy doesn't require authentication.
To make the matters worse, the same small J2ME app. won't work on my
Siemens S55 either. I've defined correctly Telecom's proxy parameters
in my mobile phone. For example, phone's WAP browser works perfectly
while MIDlet can't send a simple HTTP request.
This is the code I'm using:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import java.io.*;
....
private void loadText(String sURL) {
HttpConnection c;
DataInputStream s;
String strMethodName = "loadText().";
try {
c = (HttpConnection)Connector.open(sURL, Connector.READ);
} catch (Exception ex) {
System.out.println("Error: " + strMethodName + "1");
System.out.println(ex.toString());
return;
}
try {
c.setRequestProperty("Content-Type","text/html"); // not neccessary
c.setRequestProperty("Content-Language", "en-US"); // not neccessary
c.setRequestProperty("Accept", "*/*"); // not neccessary
c.setRequestMethod(HttpConnection.GET);
} catch (Exception ex) {
System.out.println("Error: " + strMethodName + "2");
System.out.println(ex.toString());
return;
}
try {
s = new DataInputStream(c.openDataInputStream());
} catch (Exception ex) {
System.out.println("Error: " + strMethodName + "3");
System.out.println(ex.toString());
return;
}
try {
s.close();
c.close();
}
catch (Exception ex) {
System.out.println("Error: " + strMethodName + "4");
System.out.println(ex.toString());
return;
}
}
I know the code is OK because when I'm using direct connection to the
Internet, without proxy, J2ME HTTP request works just fine. I can send
GET and POST requests without any problems.
Error always occurs in:
s = new DataInputStream(c.openDataInputStream());
The error description is:
Exception: java/lang/ClassNotFoundException
Initializing class: 'com/sun/cldc/io/NetworkConnectionBase'
Initializing class: 'com/sun/cldc/io/j2me/socket/Protocol'
Exception: java/lang/ClassNotFoundException
Exception: java/io/IOException
Exception: java/io/IOException
Error: loadText().3
java.io.IOException: Error initializing HTTP tunnel connection:
HTTP/1.0 403 Forbidden
Server: squid/2.5.STABLE1
Mime-Version: 1.0
Date: Mon, 11 Oct 2004 11:13:21 GMT
Content-Type: text/html
Content-Length: 1053
Expires: Mon, 11 Oct 2004 11:13:21 GMT
X-Squid-Error: ERR_ACCESS_DENIED 0
X-Cache: MISS from wonderland.hznet.hr
X-Cache-Lookup: NONE from wonderland.hznet.hr:8001
Proxy-Connection: close
http://www.google.com/index.html
I've browsed through Google groups several times but I haven't found
any meaningful answers to this conundrum.
Please help!
Marko
just doesn't want to pass HTTP requests through a proxy.
Needless to say I've set up correctly all proxy's parameters in the
Toolkit's preferences. As a matter of fact, I'm using the same proxy
to post this message.
I'm using standard J2ME code for sending HTTP GET and POST requests.
Nothing fancy. Also, my proxy doesn't require authentication.
To make the matters worse, the same small J2ME app. won't work on my
Siemens S55 either. I've defined correctly Telecom's proxy parameters
in my mobile phone. For example, phone's WAP browser works perfectly
while MIDlet can't send a simple HTTP request.
This is the code I'm using:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import java.io.*;
....
private void loadText(String sURL) {
HttpConnection c;
DataInputStream s;
String strMethodName = "loadText().";
try {
c = (HttpConnection)Connector.open(sURL, Connector.READ);
} catch (Exception ex) {
System.out.println("Error: " + strMethodName + "1");
System.out.println(ex.toString());
return;
}
try {
c.setRequestProperty("Content-Type","text/html"); // not neccessary
c.setRequestProperty("Content-Language", "en-US"); // not neccessary
c.setRequestProperty("Accept", "*/*"); // not neccessary
c.setRequestMethod(HttpConnection.GET);
} catch (Exception ex) {
System.out.println("Error: " + strMethodName + "2");
System.out.println(ex.toString());
return;
}
try {
s = new DataInputStream(c.openDataInputStream());
} catch (Exception ex) {
System.out.println("Error: " + strMethodName + "3");
System.out.println(ex.toString());
return;
}
try {
s.close();
c.close();
}
catch (Exception ex) {
System.out.println("Error: " + strMethodName + "4");
System.out.println(ex.toString());
return;
}
}
I know the code is OK because when I'm using direct connection to the
Internet, without proxy, J2ME HTTP request works just fine. I can send
GET and POST requests without any problems.
Error always occurs in:
s = new DataInputStream(c.openDataInputStream());
The error description is:
Exception: java/lang/ClassNotFoundException
Initializing class: 'com/sun/cldc/io/NetworkConnectionBase'
Initializing class: 'com/sun/cldc/io/j2me/socket/Protocol'
Exception: java/lang/ClassNotFoundException
Exception: java/io/IOException
Exception: java/io/IOException
Error: loadText().3
java.io.IOException: Error initializing HTTP tunnel connection:
HTTP/1.0 403 Forbidden
Server: squid/2.5.STABLE1
Mime-Version: 1.0
Date: Mon, 11 Oct 2004 11:13:21 GMT
Content-Type: text/html
Content-Length: 1053
Expires: Mon, 11 Oct 2004 11:13:21 GMT
X-Squid-Error: ERR_ACCESS_DENIED 0
X-Cache: MISS from wonderland.hznet.hr
X-Cache-Lookup: NONE from wonderland.hznet.hr:8001
Proxy-Connection: close
http://www.google.com/index.html
I've browsed through Google groups several times but I haven't found
any meaningful answers to this conundrum.
Please help!
Marko