如何在 C# 中发送 HTTPS GET 请求
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/943852/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to send an HTTPS GET Request in C#
提问by
Related: how-do-i-use-webrequest-to-access-an-ssl-encrypted-site-using-https
相关:how-do-i-use-webrequest-to-access-an-ssl-encrypted-site-using-https
How to send an HTTPS GET Request in C#?
如何在 C# 中发送 HTTPS GET 请求?
回答by Kevin Newman
Add ?var1=data1&var2=data2
to the end of url to submit values to the page via GET:
添加?var1=data1&var2=data2
到 url 的末尾以通过 GET 向页面提交值:
using System.Net;
using System.IO;
string url = "https://www.example.com/scriptname.php?var1=hello";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream resStream = response.GetResponseStream();
回答by Matt Sherman
I prefer to use WebClient, it seems to handle SSL transparently:
我更喜欢使用 WebClient,它似乎可以透明地处理 SSL:
http://msdn.microsoft.com/en-us/library/system.net.webclient.aspx
http://msdn.microsoft.com/en-us/library/system.net.webclient.aspx
Some troubleshooting help here:
一些故障排除帮助在这里:
回答by nirali
Simple Get Request using HttpClient Class
使用 HttpClient 类的简单获取请求
using System.Net.Http;
class Program
{
static void Main(string[] args)
{
HttpClient httpClient = new HttpClient();
var result = httpClient.GetAsync("https://www.google.com").Result;
}
}