结合使用HTTPS和URI

时间:2019-03-22 00:25:06

标签: https uwp uri

我在UWP上编写了一个程序,该程序将文本存储在.txt文件中,然后将其发送给客户端。当使用HTTP URI时,这确实很好用,但是现在该站点使用HTTPS,程序崩溃并显示以下错误:

System.Net.Http.HttpRequestException: 'Response status code does not indicate success: 401 ().'

崩溃的行是:

Byte[] bytes = await cli.GetByteArrayAsync(uriBing);

如果我将链接更改为HTTP,则程序将再次正常运行。有人知道我该如何解决吗?还是不可能?

var uriBing = new Uri(@"https://mydomain/net/hal2001/Actions/HALSpeak/speak.txt");

//set storageFolder as the location of the local app storage folder.
StorageFolder storageFolder = ApplicationData.Current.LocalFolder;

//Create a local file to be used to write the URL file to.
StorageFile sampleFile2 = await storageFolder.CreateFileAsync("status2.txt", CreationCollisionOption.ReplaceExisting);

//Write to local file the value stored in the URL file so they match.
var cli = new HttpClient();

Byte[] bytes = await cli.GetByteArrayAsync(uriBing);

如果尝试了以下操作但仍然不满意。

   HttpClientHandler handler = new HttpClientHandler();
            handler.Credentials = new System.Net.NetworkCredential("username", "pass");
            HttpClient cli = new HttpClient(handler);

我检查了IIS服务器应用程序>“ SSL设置”,并将“ SSL设置”设置为“要求SSL”,并且客户端证书设置为“接受”。

0 个答案:

没有答案
相关问题