資源簡介
C#獲取網(wǎng)絡(luò)時(shí)間,根據(jù)百度的返回截取。有的會出現(xiàn)無法與遠(yuǎn)程服務(wù)器建立信任關(guān)系,也相應(yīng)的解決
代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Text;
using?System.Net;
namespace?KISPDA
{
????public?class?GetNetDateTime
????{
????????///
????????///?獲取網(wǎng)絡(luò)日期時(shí)間???代爽??2018-11-16
????????///? ??
????????///? ??
????????public?static?string?GetNetDateTimes()
????????{
????????????WebRequest?request?=?null;
????????????WebResponse?response?=?null;
????????????WebHeaderCollection?headerCollection?=?null;
????????????string?datetime?=?string.Empty;
????????????try
????????????{
????????????????System.Net.ServicePointManager.CertificatePolicy?=?new?TrustAllCertificatePolicy();//??代碼就可以順利和https服務(wù)器建立SSL通道
????????????????request?=?WebRequest.Create(“https://www.baidu.com“);
????????????????request.Timeout?=?3000;
????????????????request.Credentials?=?CredentialCache.DefaultCredentials;
????????????????response?=?(WebResponse)request.GetResponse();//基礎(chǔ)連接已經(jīng)關(guān)閉:?無法與遠(yuǎn)程服務(wù)器建立信任關(guān)系
????????????????headerCo
評論
共有 條評論