How to send an HTTPS GET Request in C#

C#.NetSslHttpwebrequest

C# Problem Overview


>Related: how-do-i-use-webrequest-to-access-an-ssl-encrypted-site-using-https

How to send an HTTPS GET Request in C#?

C# Solutions


Solution 1 - C#

Add ?var1=data1&var2=data2 to the end of url to submit values to the page via 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();

Solution 2 - C#

I prefer to use WebClient, it seems to handle SSL transparently:

http://msdn.microsoft.com/en-us/library/system.net.webclient.aspx

Some troubleshooting help here:

https://clipperhouse.com/webclient-fiddler-and-ssl/

Solution 3 - C#

Simple Get Request using HttpClient Class

using System.Net.Http;

class Program
{
   static void Main(string[] args)
    {
        HttpClient httpClient = new HttpClient();
        var result = httpClient.GetAsync("https://www.google.com").Result;
    }

}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionClair VengsView Question on Stackoverflow
Solution 1 - C#Kevin NewmanView Answer on Stackoverflow
Solution 2 - C#Matt ShermanView Answer on Stackoverflow
Solution 3 - C#niraliView Answer on Stackoverflow