Highcharts导出服务器的POST参数导致407代理认证错误



我正在尝试提交一个HttpRequest到Highcharts导出服务器http://export.highcharts.com,并且正在接收一个407代理认证所需的响应错误。我不认为我们需要通过海图的认证。还有人遇到这个问题吗?

// 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();
}

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

request.Proxy = WebRequest.DefaultWebProxy;
request.Credentials = System.Net.CredentialCache.DefaultCredentials;
request.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;

最新更新