这段代码应该给我JsonString作为响应。但是我得到一个错误
System.Net类型的未处理异常。在System.dll中发生WebException
附加信息:远程服务器返回错误:(415)不支持的媒体类型。
string Url = "https://abc.test.xyz.com/123456344589753/transactions";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
string certThumbPrint = "ce03c469fb6c6dewwwww21886b7c1d405d954hshgd";
X509Certificate2 cert = FindCertificateByThumbprint(certThumbPrint);
if (cert != null)
{
request.ClientCertificates.Add(cert);
}
request.Method = "GET";
request.MediaType = "application/json";
request.ContentType = "application/json; charset=utf-8";
string text;
var response = (HttpWebResponse)request.GetResponse();
using (var sr = new StreamReader(response.GetResponseStream()))
{
text = sr.ReadToEnd();
}
有解决这个错误的建议吗
来自HTTP规范:
415不支持的媒体类型
415(不支持的媒体类型)状态码表示由于负载过重,源服务器拒绝为请求提供服务是此方法的目标资源不支持的格式。格式问题可能是由于请求指定的Content-类型或内容编码,或作为检查数据的结果直接。
GET请求没有有效负载,因此与您通信的服务器可能不喜欢您在请求中指定Content-Type