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
Kanaria
Posts: 62
Registered: ‎05-30-2011
My Device: 9200

Need help about Http Request connection very urgent?

I am making an application which connects to a url and returns an XML and Strings, the problem is that every time I get this error message "The specified HTTP method is not supported".

 

So, please anyone can help ?

Please use plain text.
Developer
Alan_Hollis
Posts: 53
Registered: ‎11-13-2009
My Device: Not Specified

Re: Need help about Http Request connection very urgent?

Sounds most likley that you're not sending the right data to the server. Have you tried doing the same thing in your browser/curl?

 

Please use plain text.
Developer
Kanaria
Posts: 62
Registered: ‎05-30-2011
My Device: 9200

Re: Need help about Http Request connection very urgent?

There is a problem thta I don know what ?

When I uncheck the 'APN Settings Enabled' it gives a Timed out Exception and when I check it it works.

 

but when I write the URL in the browser it gives 'A problem occured while trying to render the page'

Please use plain text.
Developer
Alan_Hollis
Posts: 53
Registered: ‎11-13-2009
My Device: Not Specified

Re: Need help about Http Request connection very urgent?

[ Edited ]

Not sure about the APN settings bit if I'm honest. This thread ( http://supportforums.blackberry.com/t5/Java-Development/TCP-IP-APN-Setting-Enabled-check-box/td-p/3... )suggests that it should remain checked.

It still sounds to me that you're sending the wrong data to the server. Is it your own webserver you're making the request to?

 

edit: Fixed link

Please use plain text.
Developer
Kanaria
Posts: 62
Registered: ‎05-30-2011
My Device: 9200

Re: Need help about Http Request connection very urgent?

The links is not working, note that I connect using the WiFi.

 

Ok, so if you can give me a little feed about how to send data to the server would be cool :smileyhappy:.

Note that its my own webserver.

Please use plain text.
Developer
peter_strange
Posts: 19,609
Registered: ‎07-14-2008
My Device: Not Specified

Re: Need help about Http Request connection very urgent?

What OS are you developing for.

 

If you are developing fo a pre OS 5.0, or for more general information read this, especially the required reading:

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

 

There is some sample code that handles various connection circumstances including WiFi here:

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

 

You might find this useful too:

http://supportforums.blackberry.com/t5/Java-Development/Different-ways-to-make-an-HTTP-or-socket-con...

 

http://supportforums.blackberry.com/t5/Java-Development/What-Is-Network-API-alternative-for-legacy-O...

 

Please use plain text.
Developer
Kanaria
Posts: 62
Registered: ‎05-30-2011
My Device: 9200

Re: Need help about Http Request connection very urgent?

I already have read the most of these topics but still have the same problem and dont know why ?

Note that I am using the Eclipse plugin for blackberry SDK

Please use plain text.
Developer
Alan_Hollis
Posts: 53
Registered: ‎11-13-2009
My Device: Not Specified

Re: Need help about Http Request connection very urgent?

I think we're going to see some of your code and what you're expecting to see as a response.

If it's your web server that's returning the response you should be able to see what it doesn't like, and therefore why it's returning that error.
Please use plain text.
Developer
Kanaria
Posts: 62
Registered: ‎05-30-2011
My Device: 9200

Re: Need help about Http Request connection very urgent?

here is a sample code

 

 

public class HttpRequestDispatcher extends Thread {

private String url;

private String method; // GET or POST

private EntertainMain screen;


public HttpRequestDispatcher(String url, String method,EntertainMain screen) {

this.url = url;

this.method = method;

this.screen = screen;

}

public void run() {

try {

StreamConnection connection = (StreamConnection) Connector.open(url);

((HttpConnection) connection).setRequestMethod(method);
int responseCode = ((HttpConnection) connection).getResponseCode();

 

if (responseCode != HttpConnection.HTTP_OK) {

 

screen.requestFailed("Unexpected response code :"+ responseCode);

connection.close();

return;

}
String contentType = ((HttpConnection) connection).getHeaderField("Content-type");

ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream responseData = connection.openInputStream();

byte[] buffer = new byte[1000];

int bytesRead = responseData.read(buffer);

while (bytesRead > 0) {

baos.write(buffer, 0, bytesRead);

bytesRead = responseData.read(buffer);

}

baos.close();

connection.close();
screen.requestSucceeded(baos.toByteArray(), contentType);
} catch (IOException e) {

// TODO Auto-generated catch block

screen.requestFailed(e.toString());

}

}

}

Please use plain text.
Developer
peter_strange
Posts: 19,609
Registered: ‎07-14-2008
My Device: Not Specified

Re: Need help about Http Request connection very urgent?

Which line throws this Exception?

 

I presume it is this line:

 

((HttpConnection) connection).setRequestMethod(method);

 

If so, have you confirmed that method is set correctly, i.e.

HttpConnection.GET or

HttpConnection.POST

Please use plain text.