'How to pass API path variable in c#
I need to call a API (/salesandtarget/from/{startDate}/to/{endDate} ). Here is what I have coded -
HttpWebRequest httpWReq = (HttpWebRequest)WebRequest.Create(wUrl);
httpWReq.Method = "GET";
httpWReq.ContentType = "application/json";
httpWReq.Headers.Add("user-key", userKey);
HttpWebResponse httpWResp = (HttpWebResponse)httpWReq.GetResponse();
How should I pass the startDate and endDate to request. Thank you!
Solution 1:[1]
It seems like you would need to format the URL string (wURL) that is passed to the WebRequest.Create() method with your desired dates. Something like:
string wUrl = string.Format("/salesandtarget/from/{0}/to/{1}", startDate, endDate);
Where startDate and endDate are DateTimes. Pay special attention to how you need your DateTimes formatted for your request. It may require you to manually call the ToString() method with the required formatting.
You will need to create a new HttpWebRequest object for each unique URL.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Max Wesley |
