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

New Developer
Posts: 8
Registered: ‎10-10-2008
My Device: Not Specified
Accepted Solution

How to make HTTP GET request with socket?

I want to use socket to do HTTP GET but I always get 501 error back.




<title>501 Method Not Implemented</title>
<h1>Method Not Implemented</h1>
<p> to /index.html not supported.<br />
<address>Apache/2.0.52 (CentOS) Server at li43-231.members.linode.com Port 80</address>



streamConnection =
            (StreamConnection) Connector.open(getUrl(3)+APN_STR,Connector.READ_WRITE);
            // create DataOuputStream on top of the socket connection
            outputStream = streamConnection.openOutputStream();
            dataOutputStream = new DataOutputStream(outputStream);
            // send the HTTP request
            dataOutputStream.writeChars("GET /index.html http/2.0\n");
            dataOutputStream.writeChars("host: badev.liveblockauctions.com\n");

            // create DataInputStream on top of the socket connection
            inputStream = streamConnection.openInputStream();
            dataInputStream = new DataInputStream(inputStream);
            // retrieve the contents of the requested page from Web server
            int inputChar;
            int size=0;
            StringBuffer results=new StringBuffer();
            while ( (inputChar = dataInputStream.read()) != -1) {
                results.append((char) inputChar);


JDE 4.6 and blackberry bold.


Any suggestion?


Thanks a lot!

Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: How to make HTTP GET request with socket?

see many of my earlier posts with links to ietf and suggestions on setting up dummy servers with known working

requestors- I use wget with cygwin or IE and a perl server socket. I think the get needs something about http1.x or something

but I'd have to look,


$ perlform -serve 80
GET /something.dum HTTP/1.0
User-Agent: Wget/1.9.1
Accept: */*
Connection: Keep-Alive

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

Re: How to make HTTP GET request with socket?

[ Edited ]

Here is some code that I use to do something like what you want.  I suspect that if looked you at the bytes that you send as a result of your writeChars(), you will find it doesn't match the http spec.  For example, I think you need CRLF, whereas I think you are just sending LF at the end of each line.  However I'm not an http expert, I just got this going for something I was working on.  Hopefully you can use it to get your code working.


Note that the URL I use is _target + ":80", _requestString is just the GET request String and RegisterCF.getEmailAddress(), just gets this device's email address.


c = (StreamConnection)Connector.open(completeURL); is = c.openInputStream(); os = c.openOutputStream(); String sendString = "GET " + _requestString + " HTTP/1.0 \r\n" + "Host: " + _target + "\r\n" + "From: " + RegisterCF.getOurEmailAddress() + "\r\n" + "\r\n"; os.write(sendString.getBytes()); os.close();






Message Edited by peter_strange on 10-17-2008 06:31 PM