ASP.NET WebRequest到Highcharts导出服务器
发布时间:2020-12-16 06:32:17 所属栏目:asp.Net 来源:网络整理
导读:我需要在PDF报告中包含一个highcharts图表.但是如何获得export.highcharts.com生成的image / png? 这就是我到目前为止所做的事情: 单击按钮,将触发此ajax请求: $.ajax({ url: "Home/Teste",type: "POST",dataType: "html",data: { svgParam: myChart.getS
我需要在PDF报告中包含一个highcharts图表.但是如何获得export.highcharts.com生成的image / png?
这就是我到目前为止所做的事情: 单击按钮,将触发此ajax请求: $.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,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(); } } 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> 为了测试,我在我的应用程序中创建了另一个方法,以接收此WebRequest,如下所示: [HttpPost] [ValidateInput(false)] public void Teste2(string filename,string type,string width,string svg) { string whereIsMySvg = svg; } 接收filenam,type和width参数.但是svg one是null.我试图编码,不编码,序列化为json字符串,更改内容类型……什么都没有,svg参数永远不会到达目的地. 有任何想法吗? 解决方法
如果您复制并粘贴了代码并且这不是印刷错误,则会将请求参数中的“svg”错误地发送到导出服务器.你有“sgv”.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- ASP.NET(.asmx)webservices中的客户端IP地址
- 在基本控制器中覆盖ASP.NET MVC中的OnAuthorization
- ASP.NET Web API中除IQueryable之外的OData查询和类型
- asp.net – Databound和Databind之间的区别
- asp.net – 如何根据属性值更新设计时UserControl接口?
- asp.net-mvc – 如何缓存FileContentResult的性能?
- 进程是经典ASP可以存储会话状态的唯一方法吗?
- asp.net – 在网页上显示文本时,Replace(Environment.NewLi
- 使用Reporting Services(SSRS)作为ASP.NET Core站点中的引用
- asp.net – 如何引用一个javascript文件?
推荐文章
站长推荐
- asp.net-mvc – 在ASP.NET MVC Preview 4中使用路
- asp.net – Windows Workflow Foundation的替代方
- asp.net-mvc – 模型支持DB上下文已更改;考虑代码
- asp.net-mvc – 如何在ASP.NET MVC的同一页面中使
- asp.net-mvc – 在ServiceStack服务上进行身份验
- asp.net正则表达式验证器客户端脚本错误
- asp.net 发布WebService出现的各种问题及解决方法
- 如何在ASP.NET网站项目中使用最新的VB.NET语言级
- asp.net-mvc – 默认的AccountController示例何时
- asp.net-mvc – 我如何可以渲染局部视图在asp.ne
热点阅读