I wrote a class to make HTTP POST requests easier. But I get a NullReferenceException here :
public async Task ResponseString() {
m_responseString = await m_response.Content.ReadAsStringAsync();
}
I checked m_response with the debugger, which it is null :
public async Task Response(string requestUri) {
m_response = await m_client.PostAsync(requestUri, m_content);
}
I think it is a problem of synchronization, here is the main function :
static void Main(string[] args) {
/*var values = new Dictionary<string, string> {
{ "thing1", "hello"},
{ "thing2", "world"}
};
var content = new FormUrlEncodedContent(values);
var response = await client.PostAsync("http://www.example.com/recepticle.aspx", content);
var responseString = await response.Content.ReadAsStringAsync();*/
HttpsRequestPostExample httpsRequestPostExample = new HttpsRequestPostExample();
Dictionary<string, string> values = httpsRequestPostExample.Values(
new Dictionary<string, string> {
{ "thing1", "hello"},
{ "thing2", "world"}
});
FormUrlEncodedContent content = httpsRequestPostExample.Content();
Task response = httpsRequestPostExample.Response("http://www.example.com/recepticle.aspx");
Task responseString = httpsRequestPostExample.ResponseString();
}
ResponseString is called after Response.