开发者

Suggest encoding which removes slashes which I can use as the format for REST-style URL-paramteters

Given a path to a REST style URL:

http://site.com/rest/customer/foo/robot/bar/1

When you GET it, it returns a PDF to the foo-customer containing page 1 of the bar-URL.

While foo is the name of the customer bar is an URL. The URL usually contains slashes and might look something like this:

http://anothersite.com/interestingarticle.html

As REST URL's separate开发者_运维百科 arguments by slashes I can't just put it into the REST URL above. Which encoding should I use? I can't use Base 64 as it utilizes the slash as well.

As a technical note I will encode the URL in a .NET-application and decode it in PHP.


What is your use case exactly? Why does bar need to be a URL? The server can construct the URIs any way it wants to.

If you for some reason MUST use the URL, do this:

http://site.com/rest/customer/foo/robot?bar=http://anothersite.com/interestingarticle.html&page=1

(with urlencoded query string of course).


By double URL-encoding the URL it will never contain any slashes and may therefore use parameters separated by slashes.

The URL is encoded and sent from .NET using C#:

String url = "http://urltoencode.com/a/page";
System.Text.Encoding westernEuropeanISOencoding = System.Text.Encoding.GetEncoding("iso-8859-1");
String doubleEncodedUrl = System.Web.HttpUtility.UrlEncode(url, westernEuropeanISOencoding);
doubleEncodedUrl = System.Web.HttpUtility.UrlEncode(doubleEncodedUrl, westernEuropeanISOencoding);

The receiving PHP-script double decodes the URL:

url = decode(decode($receivedDoubleEncodedUrl));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜