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
milan555
Posts: 52
Registered: ‎07-04-2011
My Device: Bold-3
My Carrier: Developer

Response code : 505

Hi,

I try to parse below webservice using Http Connection.

 

http://query.yahooapis.com/v1/public/yql?q=select * from weather.bylocation where location='Goodlettsville, Tennessee' and unit='f';&diagnostics=true&env=store://datatables.org/alltableswithkeys

 

when I parse this url I got response code : 505 .

So, if any one has any idea please help me.

 

Thanks,

 

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

Re: Response code : 505

I presume that this is the http response code and that you have checked out what that actually means?

 

I suspect the problem here is that you are not URL encoding the URL and the yahoo server is getting confused regarding what you are asking it to do. 

 

Here is a reference for URL Encoding - I would URL encode all the special characters, before sending the request, especially the spaces....

http://www.w3schools.com/tags/ref_urlencode.asp

Please use plain text.
Regular Contributor
milan555
Posts: 52
Registered: ‎07-04-2011
My Device: Bold-3
My Carrier: Developer

Re: Response code : 505

Hi,

Thanks for Reply.

 

But the URL which I have used in that URL I did not find any special character.

 

http://query.yahooapis.com/v1/public/yql?q=select * from weather.bylocation where location='Goodlettsville, Tennessee' and unit='f';&diagnostics=true&env=store://datatables.org/alltableswithkeys

 

I got response code : 505, which means HTTP version not supported.

 

So,If I there in any mistake done by me  to understand your post then sorry.

But When I throw that URL in browser I got proper response.

 

Thanks,

 

Please use plain text.
Regular Contributor
milan555
Posts: 52
Registered: ‎07-04-2011
My Device: Bold-3
My Carrier: Developer

Re: Response code : 505

Yes,you have presumed right.
Its HTTP response code : 505.
I think which means which means HTTP version not supported.

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

Re: Response code : 505

I don't understand how you can say this:

"I did not find any special character"

 

when I specifically said this:

"I would URL encode all the special characters ... especially the spaces."

 

and the page I referenced says this:

"URLs cannot contain spaces. URL encoding normally replaces a space with a + sign."

 

Following is the URL I think you should be using - I encoded your supplied URL using the "URL Encode" button on the page I sent you too:

 

http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.bylocation%20where%20location...

 

Is this clearer?

Please use plain text.
Regular Contributor
milan555
Posts: 52
Registered: ‎07-04-2011
My Device: Bold-3
My Carrier: Developer

Re: Response code : 505

OK.

Thanks for reply.

 

So,you are asking to parse below URL, right ?

 

http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.bylocation%20where%20location...

 

I will check this and revert back to you, that which HTTP response code I will get after parsing this URL.

 

Thanks,

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

Re: Response code : 505

Not sure you understand so I will explain again, hopefully clearer...

 

I am not an expert on this, but as I understand it, the URL that you send must be URL Encoded.   This is because HTTP web servers do not typically understand special characters like spaces in the URL.  To get over this restriction but still make sure that URLs can include characters like spaces, Browsers and other things using Web Servers will URL Encode the String that they send when they request a connection.  The Web Server will decode the requested String to process it. 

 

Actaully it is not even that simple, as the following link will tell you:

http://www.lunatech-research.com/archives/2009/02/03/what-every-web-developer-must-know-about-url-en...

 

I don't know how other people have done it, but bascially I have a URL Encoder that converts 'special characters' in the 'get' part of the URL.  Here it is, use it if you wish, but it comes with no warranty or responsibility.  It is just an implementation of the URL Encoding Reference section from the original page I sent you. 

 

    // Unreserved punctuation mark/symbols
    // Used by helper URL Encode routine
    private static String MARK = "-_.!~*'()\"";

    // Static helper routine - encodes URL data

    /**
     * Encodes a URL - This method assumes UTF-8
     * @param url URL to encode
     * @return the encoded URL
     */
    public final static String URLencode(String url) {
        StringBuffer encodedUrl = new StringBuffer(); // Encoded URL
        int len = url.length();
        // Encode each URL character
        for(int i = 0; i < len; i++) {
            char c = url.charAt(i); // Get next character
            if ((c >= '0' && c <= '9') ||
                (c >= 'a' && c <= 'z') ||
                (c >= 'A' && c <= 'Z'))
                // Alphanumeric characters require no encoding, append as is
                encodedUrl.append(c);
            else {
                int imark = MARK.indexOf(c);
                if (imark >=0) {
                    // Unreserved punctuation marks and symbols require
                    //  no encoding, append as is
                    encodedUrl.append(c);
                } else {
                    // Encode all other characters to Hex, using the format "%XX",
                    //  where XX are the hex digits
                    encodedUrl.append('%'); // Add % character
                    // Encode the character's high-order nibble to Hex
                    encodedUrl.append(toHexChar((c & 0xF0) >> 4));
                    // Encode the character's low-order nibble to Hex
                    encodedUrl.append(toHexChar (c & 0x0F));
                }
            }
        }
        return encodedUrl.toString(); // Return encoded URL
    }

 

 

Please use plain text.
Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Response code : 505

You might also consider using the API method URLEncodedPostData.

 

For example:

 

public String getURL()
{
    URLEncodedPostData postData = new URLEncodedPostData(URLEncodedPostData.DEFAULT_CHARSET, true);
        
    postData.append("id",Integer.toString(m_locationId));
    postData.append("text",m_checkinText);
        
    return BASE_SERVER_URL + "/places/update_location" + "?" + postData.toString();
}

 

 

 

Please use plain text.
Regular Contributor
milan555
Posts: 52
Registered: ‎07-04-2011
My Device: Bold-3
My Carrier: Developer

Re: Response code : 505

Hi,

I tried your code but still getting the http response code : 505.

Regards,

 

Please use plain text.
Regular Contributor
milan555
Posts: 52
Registered: ‎07-04-2011
My Device: Bold-3
My Carrier: Developer

Re: Response code : 505

Hi,

Thanks for reply.

I tried your code but still getting the http response code : 505.

Regards,

Please use plain text.