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

时间:2013-05-24 23:35:19

标签: highcharts

我正在尝试向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();
            }

1 个答案:

答案 0 :(得分:0)

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

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