简体   繁体   中英

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 .

This request throws an error as we have an apostrophe in the URI ie, 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" .

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

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

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) + $"\";";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM