1

我正在尝试向 Highcharts 导出服务器http://export.highcharts.com提交 HttpRequest ,并且从响应中收到 407 Proxy Authentication required 错误。我认为我们不需要将身份验证传递给 Highcharts。还有其他人遇到这个问题吗?

// Create a request using a URL that can receive a post. 
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://export.highcharts.com/");
// Set the Method property of the request to POST.
request.Method = "POST";

// Create POST data and convert it to a byte array.
string options2 = "{xAxis:{categories:['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']},series:[{data:[29.9,71.5,106.4,129.2,144.0,176.0,135.6,148.5,216.4,194.1,95.6,54.4]}]}";
string postData = string.Format("const={0}&type={1}&width={2}&options={3}&content=options", "chart", "image/png", 1270, options2);
//string postData = string.Format("filename={0}&type={1}&width={2}&svg={3}", "chart", "image/png", 1270, "TEST");

byte[] byteArray = Encoding.UTF8.GetBytes(postData);

// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded; multipart/form-data";

// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Get the request stream.
Stream dataStream = request.GetRequestStream();
// Write the data to the request stream.
dataStream.Write(byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close();
// Get the response.
WebResponse response = request.GetResponse();

HttpWebResponse webResponse = (HttpWebResponse)request.GetResponse();
//This is here just to read the response.
string msg;
using (StreamReader sReader = new StreamReader(webResponse.GetResponseStream()))
{
    msg = sReader.ReadToEnd();
}
4

1 回答 1

0

我需要将代理设置添加到我的 HttpRequest。添加以下代码行后,我的响应是返回一个高图图像。

request.Proxy = WebRequest.DefaultWebProxy;
request.Credentials = System.Net.CredentialCache.DefaultCredentials;
request.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
于 2013-05-25T13:58:35.057 回答