【问题标题】:While sending a post request with large data in request body in IISnode not working in IIS在 IISnode 的请求正文中发送包含大数据的发布请求时,在 IIS 中不起作用
【发布时间】:2021-06-12 18:54:49
【问题描述】:

我在 ASP.net 上构建了一个客户端应用程序,并以 Nodejs 和 express 为后盾,托管在 IIS 版本 10 的 Windows Server 2016 上。 当我将请求正文中包含大量数据的发布请求发送到 API 端点时,它会在 2 分钟后在浏览器控制台中返回 net::ERR_CONNECTION_RESET 错误。这早些时候工作正常,突然它开始给出这个错误。 当我在请求正文中传递小数据时它工作正常,但是当它超过 320 时,它没有达到终点并在 2 分钟后在控制台 net::ERR_CONNECTION_RESET 上给出错误消息。

  1. 传入请求正文的数据
[{ProductId: "352561", Country: "United State"}, {ProductId: "364321", Country: "China"}]
[0 … 99]
[100 … 199]
[200 … 299]
[300 … 302]
  1. 我从其中向 api 端点发出请求的 Aspx 页面
makePostRequest('http://localhost:3000/searchMultiple', tableData);

async function makePostRequest(path, tableData) {
        const result = await fetch(path, {
            method: 'POST',
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json'
            },
            body: JSON.stringify(tableData)
        });
        //console.log(result);
        const data = await result.json();
}
  1. 节点 API 端点
app.post('/searchMultiple', (request, response) => {

    tableData = request.body;
    if (tableData.length > 0) {

        searchMultipleProduct(tableData)
            .then(results => {
                //Returns a 200 Status OK with Results JSON back to the client.
                response.status(200);
                response.json(results);
            });
    } else {
        response.end();
    }
});
  1. 服务器端 web 配置文件 IISNode
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <handlers>
            <add name="iisnode" path="server.js" verb="*" modules="iisnode" />
        </handlers>
        <rewrite>
            <rules>
                    <rule name="nodejs">
                        <match url="(.*)" />
                        <conditions>
                            <add input="{REQUEST_FILENAME}" matchType="IsFile" pattern="" ignoreCase="true" negate="true" />
                        </conditions>
                        <action type="Rewrite" url="server.js" />
                    </rule>
            </rules>
        </rewrite>
     
        <security>
            <requestFiltering>
                <requestLimits maxAllowedContentLength="4294967295"  />
                <hiddenSegments>
                    <add segment="node_modules" />
                    <add segment="iisnode" />
                </hiddenSegments>
            </requestFiltering>
        </security>
        
    </system.webServer>
</configuration>
  1. 客户端网络配置文件
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.7.2" />
    <httpRuntime targetFramework="4.7.2" />
    <pages>
      <namespaces>
        <add namespace="System.Web.Optimization" />
      </namespaces>
      <controls>
        <add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt" />
      </controls>
    </pages>
  </system.web>
    <system.web.extensions>
        <scripting>
            <webServices>
                <jsonSerialization maxJsonLength="2147483647" />
            </webServices>
        </scripting>
    </system.web.extensions>
</configuration>

任何帮助/指针/链接/任何东西都将不胜感激。

【问题讨论】:

    标签: node.js asp.net express iisnode


    【解决方案1】:

    我认为您的问题可能在POST : /searchMultiple 路线内。

    app.post('/searchMultiple', (request, response) => {
    
        tableData = request.body;
        if (tableData.length > 0) {
    
            searchMultipleProduct(tableData)
                .then(results => {
                    //Returns a 200 Status OK with Results JSON back to the client.
                    response.status(200);
                    response.json(results);
                });
        } else {
            response.end();
        }
    });
    

    这将帮助您缩小问题是否与您的数据库连接有关。由于 CONNECTION RESET 意味着响应花费的时间比 IIS 超时时间长,您可以从 increasing your IIS timeouts 开始,或者您可能只需要在异步 searchMultipleProduct 函数中添加一条 catch 语句。添加 catch 语句可能有助于发送响应错误(如果该错误是由于大数据引起的,现在您将能够通过错误响应来判断)。

    app.post('/searchMultiple', (request, response) => {
    
        tableData = request.body;
        if (tableData.length > 0) {
    
            searchMultipleProduct(tableData)
                .then(results => {
                    //Returns a 200 Status OK with Results JSON back to the client.
                    response.status(200);
                    response.json(results);
                }).catch(err => {
                    resp.status(500).send(err));
                });
        } else {
            response.end();
        }
    });
    

    【讨论】:

    • 嗨,马特 - 我已经尝试过你的方法,将 IIS 10 中的超时时间从 120 秒增加到 240 秒,但是如果我在请求正文中传递的数据超过 300 项,它不会到达 api 端点.相反,当我传递的数据少于 250 项时,它工作正常。我在应用程序中没有数据库依赖性。我检查了 IIS 10 中的日志,它显示 sc-status - 200。我不确定后台发生了什么。
    猜你喜欢
    • 2021-10-24
    • 1970-01-01
    • 2021-08-29
    • 2018-10-06
    • 1970-01-01
    • 2017-05-04
    • 1970-01-01
    • 2017-05-15
    • 1970-01-01
    相关资源
    最近更新 更多