06-28-2011 06:28 AM
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 ?
06-28-2011 06:32 AM
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?
06-28-2011 06:40 AM
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'
06-28-2011 06:49 AM - edited 06-28-2011 07:22 AM
Not sure about the APN settings bit if I'm honest. This thread ( http://supportforums.blackberry.com/t5/Java-Develo
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
06-28-2011 07:10 AM
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
.
Note that its my own webserver.
06-28-2011 07:25 AM
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:
There is some sample code that handles various connection circumstances including WiFi here:
You might find this useful too:
06-28-2011 07:50 AM
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
06-28-2011 07:56 AM
06-28-2011 08:00 AM
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());
}
}
}
06-28-2011 08:25 AM
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