Arya raj

Arya raj

  • NA
  • 57
  • 33.5k

how to pass query string and path paramter in httpgetasync

Jul 30 2019 3:39 AM
I need to pass query string and path parameters to HttpClient GetAsync() method in .NET
 
File/{document_id}?version={version_number}
  1. [Route("api/drs/v1/document/getdetails/{Id}")]  
  2. [HttpGet] public async Task<HttpResponseMessage> DocumentDetails(HttpRequestMessage details)  
  3. { // Debugger.Launch();  
  4. try {  
  5. using (HttpClient client = new HttpClient()) {  
  6. client.DefaultRequestHeaders.Accept.Clear(); //String path=Request.Url.GetLeftPart(UriPartial.Path);  
  7. HttpResponseMessage response = await client.GetAsync("http://localhost:8089/api/drs/v1/document/Files/"]);  
  8. if (response.IsSuccessStatusCode) {  
  9. Console.Write("Success"); }  
  10. else { Console.Write("Failure");  
  11. } return response; }  
  12. } catch (Exception e)  
  13. { throw e; } }  

Answers (1)