【发布时间】:2017-12-01 17:24:58
【问题描述】:
需要一些帮助来解决问题。第一次这样做,我读过的所有内容似乎都没有帮助。我正在尝试从 api 调用中获取响应并在我的标签中取回结果,但我得到的只是标签中的 System.Net.HttpWebRequest,因此它至少发送和返回。 我还需要做些什么来获得预期的响应吗?
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
WebRequest req = WebRequest.Create(@"https://server.net/api/v1/.." + Id_TextBox.Text);
req.Method = "POST";
req.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes("Login:######"));
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();//(HttpWebResponse)req.GetResponse() as HttpWebResponse;
myString_Label.Text = req.ToString();
谢谢!
【问题讨论】:
-
通过对请求对象调用 ToString(),您将获得对象的字符串表示形式。您可能希望在 resp 上调用 ToString(),或者将响应反序列化为您可以显示的对象。