c# - Json文件请求产生“(413)请求实体太大”。

标签 c# .net json webserver powerbi

我有一个超过10,000行的json文件

所以当我要求Power BI

我会收到一条错误消息

(413) Request Entity Too Large。


如果Json文件<10,000行,此代码可以工作

所以我该如何解决有关行太糊的问题

这是我的代码

string ColumnValuesJson = System.IO.File.ReadAllText(@"PowerBI_Column_Values.json");

//POST web request
byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(ColumnValuesJson);

request.ContentLength = byteArray.Length;

Console.WriteLine(byteArray.Length);
Console.ReadLine();
//
using (Stream writer = request.GetRequestStream())
{
    writer.Write(byteArray, 0, byteArray.Length);
    var response = (HttpWebResponse)request.GetResponse();

    /*Time*/
    ProcessTime.Stop();
    Console.WriteLine("20,000 Rows  {0} ms", ProcessTime.ElapsedMilliseconds);
    Console.ReadLine();
}

最佳答案

当请求正文大于服务器配置为允许的大小时,会出现413错误。根据您的网络服务器(以及是否可以访问它),按照以下方法进行修复:


Apache:在您的httpd.conf文件或本地.htaccess文件中设置LimitRequestBody指令。 (https://stackoverflow.com/a/3719358/1688568
Nginx:在nginx.conf(http://www.cyberciti.biz/faq/linux-unix-bsd-nginx-413-request-entity-too-large/)中设置client_max_body_size指令
IIS:设置uploadreadaheadsize配置设置(http://blogs.msdn.com/b/jiruss/archive/2007/04/13/http-413-request-entity-too-large-can-t-upload-large-files-using-iis6.aspx


如果您不是服务器的所有者,则可以尝试上传较小的压缩文件或使用multipart/form-data Content-Type发送请求。 Here是如何执行此操作的一些示例。

如注释中的结论所示,您想在AddRows上调用Power BI REST API方法。在limitations中提到每个请求只能添加1万行。最简单的方法是将json文件解析为数组并发送多个请求。要在c#中解析JSON,您可以看一下this article

关于c# - Json文件请求产生“(413)请求实体太大”。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41065851/

相关文章:

PHP json_encode 具有资源类型的 debug_backtrace()

android - 使用 spring 忽略 Jackson 中的无效值

c# - 如何通过 Web 应用程序向 Azure 通知中心注册远程设备

c# - Azure 服务结构 : not accepting normal or portable class libraries

c# - 使用 C# 驱动程序按名称打开 MongoDB GridFS

c# - Visual Studio 错误 : "The debugger cannot unwind to this frame." on any exceptions

c# - DAL和BO层Singleton的正确使用?

c# - 后台对象的初始化

json - 为什么从 JSON 返回的值不能与 NSNull 相比较?

.net - 使用 FTPWebRequest 列出文件时出现问题