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
Regular Contributor
Posts: 83
Registered: ‎05-24-2011
My Device: Storm 9550
My Carrier: XXX
Accepted Solution

HTTP response code 400

Hi,

 

I am trying to set up an HTTP connection with a website to grab some info and update my SQLite database. I am using the MDS in my simulator and I keep getting a HTTP response code 400 when I try to access the web page. Just to test, I tried setting up a connection with http://google.com/ and that worked great. Thinking it was a problem then with my url, I copied the url I am using into the browser on my computer, and it worked fine. Any suggestions?

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: HTTP response code 400

'400' is "Bad Request". This usually has something to do with the formatting of the request parameters. For example, the complete URL should be "URL Encoded" (which means that blanks and other special characters are replaced by special character sequences which can be read ny the web server).

 

 

Regular Contributor
Posts: 83
Registered: ‎05-24-2011
My Device: Storm 9550
My Carrier: XXX

Re: HTTP response code 400

Thanks. I'm thinking that is the issue due to the fact that my url has spaces. I tried converting my url with this code and I got the same error. Is this the right way to do it?

 

 

       private String encodeUrl(String hsURL) {
           URLEncodedPostData urlEncoder = new URLEncodedPostData("UTF-8", false);
           urlEncoder.setData(hsURL);
           hsURL = urlEncoder.toString();
           return hsURL;
   }

 

Regular Contributor
Posts: 83
Registered: ‎05-24-2011
My Device: Storm 9550
My Carrier: XXX

Re: HTTP response code 400

Got it to work. I just used url = url.replace(' ', '+');

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: HTTP response code 400

I would suggest using the class UrlEncodedPostData. This handles all URL encoding issues.

 

See the javadocs.