ASP.NET WebRequest到Highcharts导出服务器
我需要在PDF报告中包含highcharts图表。但是我如何获得export.highcharts.com生成的图像/png? 这就是我到目前为止所做的: 单击一个按钮,就会触发此ajax请求:ASP.NET WebRequest到Highcharts导出服务器,highcharts,export,webrequest,Highcharts,Export,Webrequest,我需要在PDF报告中包含highcharts图表。但是我如何获得export.highcharts.com生成的图像/png? 这就是我到目前为止所做的: 单击一个按钮,就会触发此ajax请求: $.ajax({ url: "Home/Teste", type: "POST", dataType: "html", data: { svgParam: myChart.getSVG() }, success: function (data) { doStu
$.ajax({
url: "Home/Teste",
type: "POST",
dataType: "html",
data: { svgParam: myChart.getSVG() },
success: function (data) {
doStuff(data);
}});
在服务器上,我按照如下方式获取请求和处理:
[HttpPost]
[ValidateInput(false)]
public void Teste(string svgParam)
{
// 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 postData = string.Format("filename={0}&type={1}&width={2}&sgv={3}", "chart", "image/png", 1270, Server.UrlEncode(svgParam));
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded; multipart/form-data";
//User agent is based in a normal export.js request
request.UserAgent = @"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0";
// 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();
}
}
[HttpPost]
[ValidateInput(false)]
public void Teste2(string filename, string type, string width, string svg)
{
string whereIsMySvg = svg;
}
svgParam是一个html字符串,其内容如下:
我在asp.net中获得此svgParam没有问题。但是export.highcharts.com的响应总是相同的,就好像没有发送te svg一样:
<body>
<div id="top">
<a href="http://www.highcharts.com" title="Highcharts Home Page"
id="logo"><img alt="Highcharts Home Page"
src="resources/Highcharts-icon-160px.png" border="0"></a>
<h1>Highcharts Export Server</h1>
</div>
<div id="wrap">
<h3>Oops..,</h3>
<p>The manadatory svg POST parameter is undefined.</p>
</div>
</body>
接收到filenam、type和width参数。但是svg参数为空。我尝试编码,不编码,序列化为json字符串,更改内容类型……但什么都没有,svg参数永远无法到达目标
有什么想法吗?如果您复制并粘贴了代码,而这不是一个印刷错误,那么您在发送到导出服务器的请求参数中错贴了“svg”。您有“sgv”“我需要同样的解决方案。你做的?您能帮助我吗?您不必使用ajax调用和web方法,只需将SVG存储在
hiddenField
中,然后将其放在服务器端,以避免此类打字错误。我建议您使用