[英]Encoding apostrophe in GET API request via "HttpUtility.UrlEncode" and "Uri.EscapeDataString" gives error
I am making a GET request from postman and I am expecting list of tables in return: Following is the URI: https://XYZ/api/Sam's Club Operations Executive P&L Report DS/Tables
.我正在从 postman 发出 GET 请求,我期待得到返回的表格列表:以下是 URI:
https://XYZ/api/Sam's Club Operations Executive P&L Report DS/Tables
。
This request throws an error as we have an apostrophe in the URI ie, Sam's .这个请求会抛出一个错误,因为我们在 URI 中有一个撇号,即Sam's 。
I tried HttpUtility.UrlEncode and Uri.EscapeDataString and while debugging i can see the ' of Sam's being encoded to Sam%27s and URI looks like "Sam%27s%20Club%20Operations%20Executive%20P%26L%20Report%20DS"
.我尝试了 HttpUtility.UrlEncode 和 Uri.EscapeDataString,在调试时我可以看到Sam 的''被编码为Sam%27s ,URI 看起来像
"Sam%27s%20Club%20Operations%20Executive%20P%26L%20Report%20DS"
。
However, when i am trying to open a connection, I am thrown with exception.然而,当我试图打开一个连接时,我抛出了异常。 My connection string Catalog field looks like:
Catalog=Sam%27s%20Club%20Operations%20Executive%20P%26L%20Report%20DS;
我的连接字符串目录字段如下所示:
Catalog=Sam%27s%20Club%20Operations%20Executive%20P%26L%20Report%20DS;
. .
The exception thrown is:抛出的异常是:
{"Either the database 'Sam%27s%20Club%20Operations%20Executive%20P%26L%20Report%20DS' does not exist, or you do not have permissions to access it.\r\n\r\n Technical Details:\r\nRootActivityId: f626f5b7-b8ed-4697
{“数据库‘Sam%27s%20Club%20Operations%20Executive%20P%26L%20Report%20DS’不存在,或者您无权访问它。\r\n\r\n 技术细节:\ r\nRootActivityId: f626f5b7-b8ed-4697
I am using basic authentication and I am sending correct username and password with each request.我正在使用基本身份验证,并且在每次请求时都发送正确的用户名和密码。 How can I overcome this exception.
我怎样才能克服这个例外。
Encode the URI as the following to make the API call: $"\"" + Convert.ToString(WHATEVERURISTRING) + $"\";";
将 URI 编码如下以进行 API 调用:
$"\"" + Convert.ToString(WHATEVERURISTRING) + $"\";";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.