发送 post 请求多部分表单数据.来自某些微软服务的错误“超过了 100 行长度限制" [英] Sending post request multipart form data. Error from some microsoft service "Line length limit 100 exceeded"

查看:27
本文介绍了发送 post 请求多部分表单数据.来自某些微软服务的错误“超过了 100 行长度限制"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此数据是从 Postman 发送的,并且有效:

This data is sent from Postman and it works:

这是一个以 200 状态通过的邮递员请求:

This is a postman request which passes with a 200 status:

POST /api/upload HTTP/1.1

Host: api.test.contoso.se

Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW

Authorization: Basic 123

User-Agent: PostmanRuntime/7.13.0

Accept: */*

Cache-Control: no-cache

Postman-Token: 089af753-fa12-46c4-326f-dfc39c36faab,c5977145-ece3-4b53-93ff-057788eb0dcf

Host: api.test.contoso.se

accept-encoding: gzip, deflate

content-length: 18354

Connection: keep-alive

cache-control: no-cache

Content-Disposition: form-data; name="Lang"

SV
------WebKitFormBoundary7MA4YWxkTrZu0gW--

Content-Disposition: form-data; name="File"; filename="/C:/Users/file.docx


------WebKitFormBoundary7MA4YWxkTrZu0gW--

Content-Disposition: form-data; name="Login"

ABC

这是我通过 Axios 向 NodeJs 提出的请求:

This is my request from NodeJs via Axios:

    const form_data = new FormData();
        form_data.append("File", fs.createReadStream(pathToFile));
        form_data.append('Login', alias.toUpperCase());
        console.log(form_data); // se output down
        const request_config = {
            headers: {
                "Authorization": "Basic 123",
                "Content-Type": `multipart/form-data; boundary=${form_data._boundary}`
            },
            data: form_data
        };

console.log(form_data):

console.log(form_data):

FormData {

  _overheadLength: 540,

  _valueLength: 13,

  _valuesToMeasure:

   [ ReadStream {

       _readableState: [ReadableState],

       readable: true,

       _events: [Object],

       _eventsCount: 3,

       _maxListeners: undefined,

       path:

        '/Users/qq/test.docx',

       fd: null,

       flags: 'r',

       mode: 438,

       start: undefined,

       end: Infinity,

       autoClose: true,

       pos: undefined,

       bytesRead: 0,

       closed: false,

       emit: [Function] } ],

  writable: false,

  readable: true,

  dataSize: 0,

  maxDataSize: 2097152,

  pauseStreams: true,

  _released: false,

  _streams:

   [ '----------------------------610001147909085905792533
Content-Disposition: form-data; name="File"; filename="test.docx"
Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document

',

     DelayedStream {

       source: [ReadStream],

       dataSize: 0,

       maxDataSize: Infinity,

       pauseStream: true,

       _maxDataSizeExceeded: false,

       _released: false,

       _bufferedEvents: [Array],

       _events: [Object],

       _eventsCount: 1 },

     [Function: bound ],

     '----------------------------610001147909085905792533
Content-Disposition: form-data; name="Login"

',

     'abc',

     [Function: bound ] ],

  _currentStream: null,

  _insideLoop: false,

  _pendingNext: false,

  _boundary: '--------------------------610001147909085905792533

我从 ASP 服务器得到的错误:Line length limit 100 exceeded

The error I get from ASP server: Line length limit 100 exceeded

我的请求中遗漏了什么?

What am I missing in my request?

推荐答案

根据github上的这两个问题:

According to these two github issues:

https://github.com/aspnet/AspNetCore/issues/2939

https://github.com/aspnet/AspNetCore/issues/3724

该问题是由于未使用正确的行尾引起的.我无法从您的代码中确切地判断问题发生在哪里,但调试它应该相当简单.

The issue is caused by a failure to use the correct line endings. I can't tell from your code exactly where the issue is occuring, but it should be fairly straightforward to debug it.

您需要使用代理 - 我发现 Fiddler 非常好.捕获来自 Postman 和您的客户的请求并进行比较.您可能需要将整个请求放入 Notepad++ 等编辑器中才能查看非打印字符.

You need to use a proxy - I find Fiddler to be very good. Capture the request from Postman and from your Client and compare them. You may need to drop the whole request into an editor like Notepad++ to be able to view the non-printing characters.

一旦发现问题,就可以直接修改以添加或删除 .

Once you find the issue, it should be straightforward to amend to add or remove as appropriate.

这篇关于发送 post 请求多部分表单数据.来自某些微软服务的错误“超过了 100 行长度限制"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆