代码很简单:
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Head,
new Uri("https://www.google.co.uk/images/branding/googlelogo/2x/googlelogo_color_120x44dp.png", UriKind.Absolute));
HttpResponseMessage response = await new HttpClient().SendRequestAsync(request);
string str = Newtonsoft.Json.JsonConvert.SerializeObject(response);
它会抛出 Newtonsoft.Json.JsonSerializationException
从' IsStronglyProtected'获取价值时出错on' Windows.Security.Cryptography.Certificates.Certificate'。
如果我请求相同的URL,但使用普通的HTTP而不是HTTPS,它可以正常工作,序列化的字符串是
{"版本":2"的StatusCode":200,"来源":2" RequestMessage" {&#34 ; RequestUri":" http://www.google.co.uk/images/branding/googlelogo/2x/googlelogo_color_120x44dp.png""方法" {"方法":" HEAD"},& #34;内容":null,"标题":{"接受编码":" gzip,deflate"},"属性&#34 ;:{}," TransportInformation" {" ServerCertificate":空," ServerCertificateErrorSeverity":0," ServerCertificateErrors":{},& #34; ServerIntermediateCertificates":{}}}" ReasonPhrase":" OK""内容" {"集管和#34 ;: {" Content-Length":" 5087"," Last-Modified":" Thu,08 Dec 2016 01:00:57 GMT" ," Content-Type":" image / png"," Expires":" Fri,2017年4月21日12:37:29 GMT" }," Headers":{" Server":" sffe"," Cache-Control":" private,max-年龄= 31536000","接受范围":"字节","日期":"星期五,2017年4月21日12:37:29 GMT"" X-的Content-Type-OPT离子":" nosniff"" X-XSS-保护":" 1;模式=块"}" IsSuccessStatusCode":真}
Newtonsoft.Json
版本是10.0.1,代码是在面向8.1的Windows应用商店应用中编写的。
我尝试使用.NET4.5的Newtonsoft.Json
库(版本为10.0.2)创建控制台项目来验证此问题,但没有此类问题。相同HTTPS网址的结果是
{" m_HttpResponseHeaders":[" X-的Content-Type-选项"" X-XSS-保护""和Alt-SVC&# 34;,"接受-范围"" Content-Length的""缓存控制""内容类型"&#34 ;日期""过期""上次修改""服务器&#34]," m_Uri":" { {3}}"" m_Certificate":空," m_Version" {"主要":1,"次要&#34 ;: 1,"生成": - 1,"修订": - 1," MajorRevision": - 1," MinorRevision" - 1} " m_StatusCode":200," m_ContentLength":5087," m_Verb":" HEAD"" m_StatusDescription&#34 ;: " OK"" m_MediaType":空}