Using System.Net.WebClient with HTTPS certificate

后端 未结 4 1260
轻奢々
轻奢々 2021-02-05 20:11

In my C# Windows client, I have a POST submission to \"the mothership\". I want the data in the submits to be secured, of course, so I paid for HostGator to issue me an SSL cert

4条回答
  •  你的背包
    2021-02-05 20:32

    If you're not using client certificates and you can access your server using https:// then your code should look like:

    private static WebClient client = new WebClient();
    private static NameValueCollection nvc= new NameValueCollection();
    
    nvc.Add(POST_ACTION, ACTION_CODE_LOGIN);
    nvc.Add(POST_EMAIL, email);
    nvc.Add(POST_PASSWORD, password);
    
    sResponse = System.Text.Encoding.ASCII.GetString(client.UploadValues(BASE_URL + ACTION_PAGE, nvc));
    

    As long as your BASE_URL uses https:// then all the data (to and from the server) will be encrypted.

    IOW using SSL/TLS from a client to a server does not require the client to do anything special (with the certificate), besides using https:// as the scheme, since the operating system provides everything (e.g. trusted roots) you need to secure the data transmission.

提交回复
热议问题