PDA

View Full Version : "+" char as field separator in a single param



Sébastien Dolard
24 Feb 2010, 10:46 AM
Hi,

I'm trying to set multliple data in one param by using "+" char.
I want that chars that need to be encoded in URL are, but not "+" chars used to separate "real data".

I need this (+):
http://127.0.0.1:6391/api/search/file?search=foo+bar
I have this (%2B):
http://127.0.0.1:6391/api/search/file?search=foo%2Bbar
I don't now how to manage this.

Here the code I use to manage this query:


/**
* Create the request Data Store
*/
var searchStore = new Ext.data.Store({
autoLoad: false,
reader: searchReader,
sortInfo: {
field: 'added',
direction: 'DESC'
},
remoteSort: true,
proxy: new Ext.data.HttpProxy({
url: '', // url is set in beforeload event
method: 'GET'
}),
listeners: {
beforeload: function(store, options){
var searchValue = document.getElementById("KSModSearchSearchTextField").value;
if (searchValue === emptySearchText) {
searchValue = "";
}

var categoryValue = document.getElementById("searchCategoryComboBox").value;
if (categoryValue === "all") {
categoryValue = "file";
}
if (categoryValue === emptyCategoryText) {
categoryValue = "file";
}
store.proxy.setUrl(KSLib.Path.root('api/search/' + categoryValue), true);
options.params.search = searchValue;
}
}
});

bclinton
24 Feb 2010, 10:51 AM
May I ask why you want to do it that way?

If you set the parameter to an array you would get a url like this:


http://127.0.0.1:6391/api/search/file?search=foo&search=2Bbar

Are you using a back end that actually expects an array of values to be specified like your example or are you parsing the query string yourself?

evanc
24 Feb 2010, 11:48 AM
"%2b" is a url encoded "+" sign. Just run it through urldecode() or whatever equivalent function you have on the server.

Sébastien Dolard
24 Feb 2010, 12:13 PM
May I ask why you want to do it that way?

If you set the parameter to an array you would get a url like this:


http://127.0.0.1:6391/api/search/file?search=foo&search=2BbarAre you using a back end that actually expects an array of values to be specified like your example or are you parsing the query string yourself?

Hi Bill,

I want to do that because it's natural, and URI rfc compliant.
My problem is not to give information to a server, but how to do it with this format.

Sébastien Dolard
24 Feb 2010, 12:25 PM
"%2b" is a url encoded "+" sign. Just run it through urldecode() or whatever equivalent function you have on the server.

Precisely not, because in this case, how do I pass "+" char to my server for a defined process?

foo+bar != foo%2Bbar, even for a server.

Example:


search=foo+bar: server will looking for "foo" AND "bar"



search=foo%2Bbar: server will looking for "foo+bar"


Example with google query:


http://www.google.fr/search?q=foo+bar



http://www.google.fr/search?q=foo%2Bbar