相关疑难解决方法(0)

使用 C# 从控制台应用程序访问 HTTPS URL

我希望我的应用程序访问指定的 HTTPS URL 并从该 URL 下载 CSV 文件。

我有以下代码:

程序.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Security;
using System.IO;

namespace httpWebRequest_Test
{
    class Program
    {
        static void Main(string[] args)
        {
            var webAddr = "https://SFTP URL/xyz.csv";
            var httpWebRequest = (HttpWebRequest) WebRequest.Create(webAddr);
            httpWebRequest.ContentType = "text/csv";
            httpWebRequest.Method = "POST";
            var httpResponse = (HttpWebResponse) httpWebRequest.GetResponse();
            //ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
            ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications);
            Stream resStream = httpResponse.GetResponseStream();
        }

        AcceptAllCertification aac = new AcceptAllCertification();

        public static RemoteCertificateValidationCallback …
Run Code Online (Sandbox Code Playgroud)

c# url ssl https

2
推荐指数
1
解决办法
5621
查看次数

标签 统计

c# ×1

https ×1

ssl ×1

url ×1