MySpace Open Platform

A Place For Developers

Welcome Developers!

in

Welcome!

in
Blogs from the OpenSocial JS Container Team

Encoding URLs in makeRequest

Hello everybody, this is a request to everyone out there using the makeRequest function.

Inside the container we are encoding all URLs and post parameters, so please don't encode them yourselves.  This will result in a double encode which will get mangled by the proxy.

If you have noticed an issue with your makeRequest function, this may be the cause.

Good:

gadgets.io.makeRequest("http://myurl.com?p=yay");

Bad (for two reasons!):

opensocial.makeRequest(encodeUriComponent("http://myurl.com?p=yay"));

The second one is bad because it: a) encodes the URL and b) uses the deprecated opensocial.makeRequest call, which is specific to OpenSocial 0.6, please update your code to be 0.7 friendly!

Thanks,

Chad 

Comments

 

John said:

Also, if your GET requests append a '?' (question mark) when there are no query parameters, the proxy will fail. So be sure only add the question mark when you actually have parameters.

April 18, 2008 3:41 PM
 

TK's Apps said:

What about:

gadgets.io.makeRequest("myurl.com("www.someurl.com));

April 18, 2008 5:15 PM
 

Roger said:

So.. when did this change magicallyhappen?

I mean.. i've been encoding my params for what.. 60+ days?  without a single issue.

I do myurl.com(x)&p2=encodeThis(y)

So i'm only encoding my actual data.. not 100% of the URL (as in your example).

So does this mean every app I have out there, for every client, is now instanly 100% broken? (with the Myspace standard, no warning -- ala moving to 0.7, ala changing the REST API url, ala I could keep going)

April 20, 2008 6:52 AM
 

TK's Apps said:

For some reason it parsed my comment. I want to know if urlencoding a parameter is ok

gadgets.io.makeRequest('h-t-t-p://www.myurl.com?anotherurl='+encodeURIComponent("h-t-t-p://www.otheurl.com?key=val"))

April 20, 2008 2:50 PM
 

Chad Russell said:

Hey, sorry for not being 100% clear, encoding your data is fine, we just need to encode the whole thing once to send it to the proxy, if the entire URL is escaped then it'll get double encoded and you may see an error.

So this should be fine:

makeRequest(myUrl + "?next=" + escape(nextUrl));

But not this:

makeRequest(escape(myUrl) + "?next=" + escape(nextUrl));

Or:

makeRequest(escape(myUrl + "?next=" + escape(nextUrl)));

April 21, 2008 10:28 AM
 

MDP JavaScript Container said:

Notable Updates from Last Push Browser Aware Resizing <button onclick="gadgets.window.adjustHeight

April 21, 2008 10:38 AM
 

The Jarmels said:

I have tried to put up my site for a group I own

"The Jarmels"

Name taken and I Have to use my name first

(url= www.myspace.com/(raysmithandthejarmels)

I want to use my groups name only

www.myspace.com/thejarmels.

Why can't I?

April 25, 2008 12:51 PM