communication between mobile browser and proxy server
hi
I am trying to connect to internet in mobile through my proxy server.I wrote codings for that.Using my code i am able to get the request from the mobile browser but the problem is i am unable to connect to the proxy server
The following is my code for sending the request to the proxyserver and getting back the response:
s = (SocketConnection)Connector.open("socket://"+hostname+":"+port);
/*OutStream to write the request to the proxy server*/
OutputStream out = s.openOutputStream(); PrintStream outw = new PrintStream(out); outw.print(requestHeader +"\r\n"); /*Inputstream to read the response from the proxy server*/ InputStream in = s.openInputStream();
/*writing the response in the browser */
byte[] buffer = new byte[1024];
int len;
while((len = in.read(buffer)) > 0) {
os.write(buffer, 0, len);
}
is my coding correct?or i need to change anything in my codings?
This coding is working fine in emulator and displaying the correct output in the desktop browser.but in mobile it is not working?
Thanks a lot
[1112 byte] By [
parvathya] at [2007-10-3 3:27:52]

What does requestHeader look like?I don't think this is going to work though...
hi deepspace
thanks for your reply.
RequestHeader is a buffer where im storing the request getting from the mobile browser
for www.google.co.in page im getting the following request
GET http://www.google.co.in/ HTTP/1.1
Host: www.google.co.in
Accept: text/html, application/vnd.wap.xhtml+xml, application/xhtml+xml, text/css, multipart/mixed, text/vnd.wap.wml, application/vnd.wap.wmlc, application/vnd.wap.wmlscriptc, application/java-archive, application/java, application/x-java-archive, text/vnd.sun.j2me.app-descriptor, application/vnd.met.ticket, application/x-wallet-appl.user-data-provision, application/vnd.oma.drm.message, application/vnd.oma.drm.content, application/vnd.wap.mms-message, application/vnd.wap.sic, text/x-co-desc, application/vnd.oma.dd+xml, */*
Accept-Charset: iso-8859-1, utf-8, iso-10646-ucs-2; q=0.6
Accept-Encoding: gzip,deflate,identity;q=0.9
Accept-Language: en
Cookie: PREF=ID=dc8dc6e63dab6e09:TM=1156324791:LM=1156324791:S=FgovcdMV93Mm4Li7
Cookie2: $Version="1"
User-Agent: Nokia6630/4.06.0 Series60/2.6 Profile/MIDP-2.0 Configuration/CLDC-1.1
x-wap-profile: "http://nds1.nds.nokia.com/uaprof/N6630r100.xml"
Do you have any idea where my code need changes?
the whole logic is wrong or im missing something?
thanks a lot
Ah, oke.
So, this does not work the way you have it.
First of all, the HTTPConnection object will take care of the GET, so you do not have control over this. so you cannot send the GET you send.
It will just send to retrieve the / from the proxy server.
But most proxys don't really need the GET to have a full URL, since they will use the Host parameter to get the host to connect to. So you should simply that parameter.
public static proxyURL = "http://myproxy.com/";
public static HTTPConnection openConnection(String url){
int firstslash = url.indexOf("/",6);
String host = url.substring(0,firstslash-1);
String path = url.substring(firstslash);
HTTPConnection conn = (HTTPConnection) Connector.open( proxyURL+path);
conn.setRequestProperty("Host",host);
return conn;
}
I guess, this should about work (didn't test it thoug).
hi deepspace, thanks a lot.my proxy is running as a vc++ server exe in an static ip.how can i specify the that url.anyway i will try itthanks a lot
just change proxyURL to your own proxy server ip...
hi deepspacethanks a loti ll try and let u know the result.thanks a lot again
hi deepspace
The idea u gave is not working.
y u asked me to use HTTPConnection?
i have to get the request from the browser and send that to the proxy server.
then only the proxy will send the reponse.
with the idea u gave i tried but the proxy is not responsding.
can u tell me how to resolve this issue?
Are you not getting anything back from the proxy? I might have made some substring mistakes.. please check that.What do you mean by "request from the browser"?
hi
yes nothing is returned from the browser
request from the browser means
whenever u type say,www.google.co.in in your browser
the following type of request will go to the proxy server,after getting the request the proxy server will check for the host address and then it connects to the webserver and get the response and send it back to the browser.
for google page the request is
GET http://www.google.co.in/ HTTP/1.1
Host: www.google.co.in
Accept: text/html, application/vnd.wap.xhtml+xml, application/xhtml+xml, text/css, multipart/mixed, text/vnd.wap.wml, application/vnd.wap.wmlc, application/vnd.wap.wmlscriptc, application/java-archive, application/java, application/x-java-archive, text/vnd.sun.j2me.app-descriptor, application/vnd.met.ticket, application/x-wallet-appl.user-data-provision, application/vnd.oma.drm.message, application/vnd.oma.drm.content, application/vnd.wap.mms-message, application/vnd.wap.sic, text/x-co-desc, application/vnd.oma.dd+xml, */*
Accept-Charset: iso-8859-1, utf-8, iso-10646-ucs-2; q=0.6
Accept-Encoding: gzip,deflate,identity;q=0.9
Accept-Language: en
Cookie: PREF=ID=dc8dc6e63dab6e09:TM=1156324791:LM=1156324791:S=FgovcdMV93Mm4Li7
Cookie2: $Version="1"
User-Agent: Nokia6630/4.06.0 Series60/2.6 Profile/MIDP-2.0 Configuration/CLDC-1.1
x-wap-profile: "http://nds1.nds.nokia.com/uaprof/N6630r100.xml"
in the code u have given the value of the host is http: only
I still don't get what browser you are referting to, and what that would have to do with J2me..
> in the code u have given the value of the host is
> http: only
Like I said, I might have make a mistake in the string cutting.. try changing the 6 to a 7.
This should actually work. If not, then you have problem, since you cannot send http://balbal.com in a GET or POST. It will only accept the path.
hi
browser im referring is wap browser in mobile.
ok i ll change and try.
the host im mentioning is eg,www.google.co.in
coz from the request the proxy will recognize this host and connects to the webserver and send back the response.
thats y im thinking that http alone the proxy is not recognizing
I know how a proxy works...."Host" is not http alone, it should be the full hostname to the webserver you want to connect to.