If you are using Internet Explorer, please remove blackberry.com from your compatibility view settings.

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
Developer
prasadr
Posts: 51
Registered: ‎10-21-2008
My Device: Bold 9000
My Carrier: Dialog

Java HTTPConnection 406 - Not Acceptable

[ Edited ]

Hi,

 

I am developing some blackberry application which use http connection. The program work fine on simulators. But when I install it to the device the http connection failed. Then I traced it by getResponseCode and getResponseMessage. Response Code = 406 Response Message = Null The program work fine with all simulators. The problem occur when I run this on the device. Please help me to sort out this issue.

 

Here is my coding.

 

 
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;
import javax.microedition.io.*;
import java.io.InputStream;
 
class WebContentProvider {
    WebContentProvider() {    }
     
    
    public void GetContent(String UserName, String Password)
    {
         
        mainwindow.lblMessage.setText("Please wait. System is validating your request");
      
            HttpConnection httpConnector = null;
             
 
            InputStream in = null;
             
 
            StringBuffer inBuffer = new StringBuffer();
             
            String response;
            int inChar;
 
             
             
            String URL="http://www.reservations.lk/test.php"  ;
 
            try {
                 
             
            //Set the URL for this connection
            httpConnector = (HttpConnection)Connector.open(URL+";WapGatewayIP=192.168.122.2;WapGatewayPort=9201;WapGatewayAPN=www.dialogwap.lk);
             
            //Set the HTTP request type
            httpConnector.setRequestMethod(HttpConnection.GET);
             
            //openInputStream initiates connection
            in = httpConnector.openInputStream();
             
            //read in all data until end of message
            while ((inChar = in.read()) != -1) {
                //append incoming chars to buffer
                inBuffer.append((char)inChar);
            }
            response = inBuffer.toString();
             
            //close the inputStream
            in.close();
             
            //close the HTTP Connection
            httpConnector.close();
             
            if(response.equalsIgnoreCase("-1"))
            {
                mainwindow.lblMessage.setText("Invalid User Name or password. Please try again.");
                 
            }
            else
            {
                settings.SiteID = response;
                UiApplication.getUiApplication().pushScreen(new sites(response));
            }
             
            } catch(Exception e){
                }
                }
}  
 
 

 

Thank you.

 

Prasad

Please use plain text.
Developer
Blanc
Posts: 638
Registered: ‎07-02-2009
My Device: Not Specified

Re: Java HTTPConnection 406 - Not Acceptable

for confirmation, did u appended the parameters ";deviceside=true" for directtcp....??

 

have you seen this thread??

http://supportforums.blackberry.com/t5/Java-Development/Connecting-your-BlackBerry-http-and-socket-c...

Thanks and Regards,
PraveenGoparaju.
Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Java HTTPConnection 406 - Not Acceptable

You need to determine which part of the network is bouncing your request.  So trace the Web Server you are targeting and see if it actually sees your request.  I suspect note, I suspect your request is being bounced by the WAP Gateway.  I think you should try a Browser request from the same device, making sure you use the WAP Browser, and see if that gets through to your Web Server.  Assuming it does, then it would appear you need to set some http Headers so that your request can be passed through.  Sorry I've no idea what you WAP gateway will require, ask your carrier.

 

Alternatively you could try an another connection method, such as direct TCP.

 

See the network sticky Thread you have already been pointed to, most significantly look at both the Networking Videos for more information.

 

I think you got this code from the coderholics site, I suggest you review my comments about this code on that site.  Most significantly, the sample http code in the HttpConnection Javadocs does set http headers.

Please use plain text.
New Developer
phucnhfpt
Posts: 119
Registered: ‎10-23-2009
My Device: Not Specified

Re: Java HTTPConnection 406 - Not Acceptable

Your problem look like my problem before. So i think your method to connect is not correct. You can see this video Media Library . 

Please use plain text.