进行POST后,在哪里可以添加GET方法?

时间:2019-01-31 14:55:16

标签: c# json api

我有一个POST方法,它将登录凭证传递给API。登录成功后,我将需要执行GET方法来检索一些数据。

   var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://url");
    httpWebRequest.ContentType = "application/json";
    httpWebRequest.Method = "POST";

    using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
    {
        string json = new JavaScriptSerializer().Serialize(new
        {
            login = "myLogin",
            password = "myPassword"
        });

        streamWriter.Write(json);
    }
    //Do I implement the GET request right here? Any advice is appreciated. 

    var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
    using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
    {
        var result = streamReader.ReadToEnd();
        Response.Write(result);
    }

1 个答案:

答案 0 :(得分:0)

我应该实现

var result = streamReader.ReadToEnd();