Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Highlighted
New Developer
Posts: 7
Registered: ‎05-18-2009
My Device: Not Specified

HttpConnection POST problem

while(true) { url=url+";deviceside=true;interface=wifi"; c = (HttpConnection)Connector.open( url, Connector.READ_WRITE,true); //c.setRequestMethod(HttpConnection.POST); //default //Dialog.alert(c.getResponseMessage()); url = c.getHeaderField("Location"); Dialog.alert(c.getResponseCode()+ " "+ url); status = c.getResponseCode(); if ((status == HttpConnection.HTTP_TEMP_REDIRECT) || (status == HttpConnection.HTTP_MOVED_TEMP) || (status == HttpConnection.HTTP_MOVED_PERM)) { // Get the new location and close the connection url = c.getHeaderField("location").trim(); c.close(); } else { break; }

Here is my code trying to get access to a website. Through the first loop I get a 302 Response Message that Redirect me to HTTP://192.168.4.40 - which I was told is the service provider's website for selling data plans. The second loop I try to follow the redirected link and got a SecurityException: Permission denied. How am I supposed to get access to the original URL ?

 

Also, a related question. I actually have a similar code for POSTing information to a script. When I run this code on the 9000 bold, I get code 302. However, I was able to upload the data on the simulator, WITH GSM network enabled. If GSM is not enabled(just wifi), the upload would fail. So my question is, I have already specified the connection interface to be WIFI, why is the simulator using GSM to do the work? and wifi still not working..

 

Thanks

 

Yang

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: HttpConnection POST problem

I have a couple of quick thoughts:

 

1. It should be +";interface=wifi" rather than +";deviceside=true;interface=wifi".  I suspect the processing is using the deviceside=true and therefore going direct.  Note that interface=wifi does not work on the simulator

 

2. The redirect seems to be to an internal IP address.  This is not likely to be available from outside the LAN.  So if you are using a BES connection, via GSM, then you will be OK.  However unless you have established this BES connection, it seems unlikely that your device will be routed through to the BES, so you might be trying to find 192.168.4.4 on the carriers network, which you probably aren't allowed to see.

New Developer
Posts: 7
Registered: ‎05-18-2009
My Device: Not Specified

Re: HttpConnection POST problem

1. It should be +";interface=wifi" rather than +";deviceside=true;interface=wifi".  I suspect the processing is using the deviceside=true and therefore going direct.  Note that interface=wifi does not work on the simulator

 

2. The redirect seems to be to an internal IP address.  This is not likely to be available from outside the LAN.  So if you are using a BES connection, via GSM, then you will be OK.  However unless you have established this BES connection, it seems unlikely that your device will be routed through to the BES, so you might be trying to find 192.168.4.4 on the carriers network, which you probably aren't allowed to see.

 

1. Yes, I have excluded the deviceside=true part, it doesn't make a differenc.

2. I think you are right but What could be the cause of this redirect URL? If I was connecting using wifi, the only possibily I can think of is that my wifi connection connects to an AP which was using a service provider that redirects me as I access the AP.