Question

I'm running a REST service on an URI likewise to

localhost/1.0/json/host/:list/

where :list is the parameter to search for. The corresponding PHP function (using Tonic)

public function get($list) {
        $list = urldecode($list);
        $list = mysql_real_escape_string($list);

is decoding and escaping any input provided. This works as long as no input has to really encoded.

The corresponding js application uses encodeURIcomponent to encode an input made in an input box

var selectedList = encodeURIComponent($('#SelectList').val());

and fires a jQuery.get to the aforementioned REST resource

$.get("http://localhost/rest/1.0/json/host/"+ selectedList + "/", function(data) {

If an input like '923/50' is selected in the input box the parameter is properly encoded

XHR at "localhost/rest/1.0/json/host/923%2F05/"

But it is still impossible to get the records connected to this param out of my db. I get 404's all the time. So my guessing is that it is not possible to encode chars like "/".

What should i do to resolve this?

Était-ce utile?

La solution

I've managed it by changing the "/" character to "|" before executing the REST-call. The encode of the Javascript parameter is working like this.

selectedHostList = encodeURIComponent(
$('#select_hostlist').val().replace('/','|'));

My PHP REST-service uses the following to convert those back into the needed values

$list = urldecode($list);
$list = mysql_real_escape_string($list);
$list = str_replace("|", "/", $list);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top