Abrufen der Antwort einer asynchronen HttpWebRequest

Ich frage mich, ob es eine einfache Möglichkeit gibt, die Antwort einer asynchronen httpwebrequest zu erhalten.

Ich habe diese Frage bereits gesehenHier Aber alles, was ich versuche, ist, die Antwort (normalerweise json oder xml) in Form eines Strings an eine andere Methode zurückzugeben, wo ich sie dann analysieren / entsprechend behandeln kann.

Hier ist ein Code:

Ich habe diese beiden statischen Methoden hier, die ich für threadsicher halte, da alle Parameter übergeben werden und es keine gemeinsamen lokalen Variablen gibt, die die Methoden verwenden?

<code>public static void MakeAsyncRequest(string url, string contentType)
{
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
    request.ContentType = contentType;
    request.Method = WebRequestMethods.Http.Get;
    request.Timeout = 20000;
    request.Proxy = null;

    request.BeginGetResponse(new AsyncCallback(ReadCallback), request);
}

private static void ReadCallback(IAsyncResult asyncResult)
{
    HttpWebRequest request = (HttpWebRequest)asyncResult.AsyncState;
    try
    {
        using (HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asyncResult))
        {
            Stream responseStream = response.GetResponseStream();
            using (StreamReader sr = new StreamReader(responseStream))
            {
                //Need to return this response 
                string strContent = sr.ReadToEnd();
            }
       }
       manualResetEvent.Set();
    }
    catch (Exception ex)
    {
        throw ex;
   }
}
</code>

Antworten auf die Frage(4)

Ihre Antwort auf die Frage