Faseeh Haris

Faseeh Haris

  • NA
  • 150
  • 3.3k

RestSharp Querystring URL issue slash appended automatically

Nov 7 2019 1:19 PM
I am trying to hit smartfile api, this api is working fine using postman, but when i add query string parameter to url it gives me error.
I need below url to be created when request send to smartfile
<a href="https://app.smartfile.com/api/2/path/info/?children=true">https://app.smartfile.com/api/2/path/info?children=true</a>[<a href="https://app.smartfile.com/api/2/path/info/?children=true" target="_blank" title="New Window">^</a>]
but when my code executes It appends slash at the end of info and give me error of forbidden link. this error is only coming due to url. below url is generating from code
<a href="https://app.smartfile.com/api/2/path/info/?children=true">https://app.smartfile.com/api/2/path/info/?children=true</a>[<a href="https://app.smartfile.com/api/2/path/info/?children=true" target="_blank" title="New Window">^</a>]
 
<pre> string urlParameters = "?children=true";
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("https://app.smartfile.com/api/2/path/info");
//Authorization added somewhere in the code,
// Add an Accept header for JSON format.
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
// List data response.
HttpResponseMessage response = client.GetAsync(urlParameters).Result;</pre>
 

Answers (1)