1

给定 REST 样式 URL 的路径:

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

当您获取它时,它会向foo -customer返回一个 PDF,其中包含bar -URL的第1页。

而 foo 是客户的名称 bar 是一个 URL。URL 通常包含斜杠,可能看起来像这样:

http://anothersite.com/interestingarticle.html

作为 REST URL 的单独参数,我不能只将其放入上面的 REST URL 中。我应该使用哪种编码?我不能使用 Base 64,因为它也使用斜线。

作为技术说明,我将在 .NET 应用程序中对 URL 进行编码,并在 PHP 中对其进行解码。

4

2 回答 2

1

你的用例到底是什么?为什么 bar 必须是 URL?服务器可以按照它想要的任何方式构造 URI。

如果您出于某种原因必须使用 URL,请执行以下操作:

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

(当然使用 urlencoded 查询字符串)。

于 2010-03-12T16:43:26.527 回答
1

通过对 URL 进行双重 URL 编码,它永远不会包含任何斜杠,因此可以使用由斜杠分隔的参数。

URL 使用 C# 从 .NET 编码和发送:

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);

接收的 PHP 脚本对 URL 进行双重解码:

url = decode(decode($receivedDoubleEncodedUrl));
于 2010-03-15T15:39:07.627 回答