我正在使用HttpWebRequest从跨域获取json结果(https://www.facebook.com/plugins/post/oembed.json/?url=posturl).我已将ContentType和Accept设置为application/json,但我总是得到text/html响应.预期的结果是JSON.
string result = string.Empty;
var request = (HttpWebRequest)WebRequest.Create("https://www.facebook.com/plugins/post/oembed.json/?url=xxxxxx");
request.ContentType = "application/json; charset=utf-8";
request.Accept = "application/json";
request.Method = "POST";
var response = (HttpWebResponse)request.GetResponse();
using (var streamReader = new StreamReader(response.GetResponseStream()))
{
result = streamReader.ReadToEnd();
}
Run Code Online (Sandbox Code Playgroud)