BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 08-15-2007, 01:54 PM   #1 (permalink)
Thumbs Must Hurt
 
Join Date: Sep 2006
Location: Ontario, Canada
Model: 9700
Carrier: Rogers
Posts: 92
Post Thanks: 0
Thanked 0 Times in 0 Posts
Question Testing HTTP connection with the emulator

Please Login to Remove!

Hey guys, I am using JDE 4.2.1 and I seem to be having a problem opening an HTTP connection.

I am start()[ing] a thread to do it, but it never opens, and the emulator never asks me to accept a connection (like the previous versions of the JDE used to)

Code:
        public void run()
        {
            //we are going to try to make an HTTP connection. If we get the value "Follow-Me.ca" back, then the HTTP works
            //otherwise this person is unable to use our app :(
            HttpConnection hc = null;
            InputStream is = null;
            //String input = "";
            OutputStream os = null;
            String responseString = "";
            try {
                hc = (HttpConnection)Connector.open("http://www.follow-me.ca/testhh.php");
                hc.setRequestMethod(HttpConnection.GET); //never get's past this point when I debug
                
                is = hc.openInputStream();
                int ch;
                while ((ch = is.read())!= -1){
                    responseString += (char)ch;
                }
                _status.setText(responseString);

            }
            catch(IOException e) { }
        }
It's nothing too advanced, but it's really bothering me, haha

Is there some sort of setting that I have to modify in the emulator?

Thanks all,
Ryan
__________________
http://www.ryannickel.com for my awesomeness!
Offline  
Old 08-15-2007, 07:09 PM   #2 (permalink)
New Member
 
Join Date: Aug 2007
Model: 8100
PIN: N/A
Carrier: ATT
Posts: 7
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Had same problem?

I never was able to get my emulator to connect http, have been doing all my testing on the hard ware itself, don't know if there's a trick to it, or if the emulator is just very limited as far as network functionality goes.

M
Offline  
Old 08-15-2007, 08:51 PM   #3 (permalink)
Thumbs Must Hurt
 
Join Date: Sep 2006
Location: Ontario, Canada
Model: 9700
Carrier: Rogers
Posts: 92
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

The strange thing is, that it's not working on the handheld either. And I know I can make HTTP connections because the Opera Mini works...

Seems strange to me!
__________________
http://www.ryannickel.com for my awesomeness!
Offline  
Old 08-15-2007, 10:00 PM   #4 (permalink)
Thumbs Must Hurt
 
Join Date: Jun 2007
Model: 8800
PIN: N/A
Carrier: GPRS
Posts: 68
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Code:
 public void httptest()  
    {
        String URL="http://www.follow-me.ca/testhh.php";
        try
        {
            HttpConnection http = (HttpConnection) Connector.open(URL);
            http.setRequestMethod(HttpConnection.GET);
            InputStream in = http.openInputStream();
            String response = "";
            int ch = 0;
            while((ch = in.read()) != -1)
                response += (char)ch;
            System.out.println(response);            
        }
        catch(Exception io)
        {System.out.println(io.getMessage());}
     }
I use this to test , and it get the results like this "Follow-Me.ca", so it's no problem of your code!

From your information, I'm confused about your JDE4.2.1 through network. As known to all ,JDE4.2.1 do not include MDS like JDE4.1.0, so I'm wondering how are you access the network by JDE4.2.1! And you can access the network by the browser include in BB for a testing!

Because I don't know the better way to access the network in JDE4.2.1, I'm using the MDS from JDE4.1.0 instead, and it works well now. But I don't know what will happen in the future! If you know a better way to access network through JDE4.2.1 , please let me know!

Thank you!
Offline  
Old 08-15-2007, 10:46 PM   #5 (permalink)
Knows Where the Search Button Is
 
Join Date: Aug 2006
Model: 7105T
Carrier: T-Mobile
Posts: 19
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Exact same problem!

Freaky!

I just came on to post the EXACT SAME THING.

This simple code, in a thread, has always worked before with the 7520 simulator:

Code:
   _hc = (HttpConnection)Connector.open("http://www.google.com/index.html");
   int rc = _hc.getResponseCode();
But, now, it hangs on the getResponseCode() call on any of the other simulators including 4.2.1. I have pulled everything out. Obviously, I am not alone. What the heck is going on??
Offline  
Old 08-15-2007, 10:48 PM   #6 (permalink)
New Member
 
Join Date: Aug 2007
Model: 8100
PIN: N/A
Carrier: ATT
Posts: 7
Post Thanks: 0
Thanked 0 Times in 0 Posts
Smile Try this

Try getting a stream connection and type casting to http connection:
as:

StreamConnection stream;
HttpConnection conn;
InputStream in;
StringBuffer buffer = new StringBuffer(dataUrl);

System.out.println("Getting user data...");
try
{
stream = (StreamConnection)javax.microedition.io.Connector. open(buffer.toString());
if ( stream!=null )
{
System.out.println("Connected.....");

conn = (HttpConnection)stream;
Offline  
Old 08-15-2007, 11:28 PM   #7 (permalink)
Thumbs Must Hurt
 
Join Date: Jun 2007
Model: 8800
PIN: N/A
Carrier: GPRS
Posts: 68
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Code:
_hc = (HttpConnection)Connector.open("http://www.google.com/index.html");
int rc = _hc.getResponseCode();
I use this to test and the value of rc is 200!

I'm using JDE4.2.1 and run on the simulator included in it
Offline  
Old 08-16-2007, 12:04 AM   #8 (permalink)
Knows Where the Search Button Is
 
Join Date: Aug 2006
Model: 7105T
Carrier: T-Mobile
Posts: 19
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Neither works...

Casting didn't work. Nothing seems to work. It's not even a 4.2.1 issue...it doesn't work on the others either. Why is it blocking?

This is so frusterating...???
Offline  
Old 08-16-2007, 12:44 AM   #9 (permalink)
Knows Where the Search Button Is
 
Join Date: Aug 2006
Model: 7105T
Carrier: T-Mobile
Posts: 19
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Figured it out...

I wasn't very familiar with what MDS is. I ran the MDS server from the JDE 4.1 and everything works now. I need to do some research... :-/
Offline  
Old 08-23-2007, 05:29 AM   #10 (permalink)
New Member
 
Join Date: Jul 2007
Model: no
PIN: N/A
Carrier: airtel
Posts: 12
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

String URL="http://www.follow-me.ca/testhh.php";

i tried like this:

String URL="http://localhost:8080/testApp/testhh.php;deviceSide=true";
you have to give deviceSide=true if you dont want to use httpconnections thru MDS.
deviceside is a parameter of connector method .you can find in documentation of javax.microedition.io
hope this'll help
regards
Offline  
Old 08-23-2007, 05:39 PM   #11 (permalink)
Knows Where the Search Button Is
 
Join Date: Jul 2007
Model: 8300
PIN: N/A
Carrier: AT&T
Posts: 25
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

The trick to get it working is to append to the URL the string ";deviceside=false"

This will make it work. I am currently using it without any problems.

To make the code more general, I am testing for MDS.
If I have MDS, I append ";deviceside=false"
if not I append ";deviceside=true"

But in your case, with the simulator, you can just directly add ";deviceside=false". This will make it work both on the simulator and on the device.

rab
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.