I want to pass a query string to the request,
if I type it on the request itself works, however if I add it to the request.Content it fails,
Here's my code
public async Task<Product> GetProducts(
IEnumerable<string> products,
DateTime startDate,
DateTime endDate)
{
var client = new HttpClient();
client.BaseAddress = new Uri(this.productDataAddress);
client.DefaultRequestHeaders
.Accept
.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var request = new HttpRequestMessage(HttpMethod.Get, "/products/datetime");
request.Headers.Add("apad-accept", "application/json");
request.Content = new StringContent(
"{\"productIds\":\"PR00001\"}",
Encoding.UTF8,
"application/json");
var response = await client.SendAsync(request);
var content = await response.Content.ReadAsStringAsync();
var result = JsonConvert.DeserializeObject<Product>(content);
return result;
}
if I amend the line var request = new HttpRequestMessage(HttpMethod.Get, "/products/datetime?productIds=PR00001");
it works
I have google it but doesn't work, any ideas of how to build the query string?
Thanks