Javascript 加上「;“内容倾斜”;发布axios请求

Javascript 加上「;“内容倾斜”;发布axios请求,javascript,axios,Javascript,Axios,我正在尝试使用axios post请求将文件发布到远程服务器。 我想在req头中添加“Content Disposition”参数 这是迄今为止我一直在使用的代码: const axios = require('axios'); async function makePostRequest() { data = { id: 15, first_name: 'Fred', last_name: 'Blair', email

我正在尝试使用axios post请求将文件发布到远程服务器。 我想在req头中添加“Content Disposition”参数

这是迄今为止我一直在使用的代码:

const axios = require('axios');

async function makePostRequest() {

    data = {
        id: 15,
        first_name: 'Fred',
        last_name: 'Blair',
        email: 'freddyb34@gmail.com'
      }

    headers = { 
        'Content-Disposition': 'attachement' 
    }
    let res = await axios.post('http://localhost:3000/users/', data, headers);

    console.log(res.request._header);
}

makePostRequest();
我想让这个参数在上传文件的元数据参数中可用。 这是我得到的结果:

POST /users/ HTTP/1.1
Accept: application/json, text/plain, */*
Content-Type: application/json;charset=utf-8
User-Agent: axios/0.21.0
Content-Length: 79
Host: localhost:3000
Connection: close
缺少内容配置

有人能帮我吗


谢谢。

post()的第三个参数是Axios配置对象,而不是headers对象<代码>标题是配置的属性

const headers = { 
    'Content-Disposition': 'attachement' 
};
const config = { headers };
let res = await axios.post('http://localhost:3000/users/', data, config);

console.log(res.request.\u头)不会做任何事情。XHR对象上没有这样的属性



注意:虽然这将设置头,但服务器不太可能对其执行任何操作,除非您为其编写了自定义逻辑<代码>内容配置
,根据HTTP中使用的是响应头。

由服务器添加头。您无法从客户端添加它。为什么要尝试将
内容处置
添加到请求中?那里通常不使用。我想上传一个文件到AWS S3 bucket,我需要添加这个头参数。这是我正在使用的代码:``var ContDispoValue='attachment';return axios.post(resp.url,resp.formData,{headers:{'Content Disposition':ContDispoValue}})``您认为可以通过服务器的get请求添加此参数吗?谢谢。虽然一个软件可以同时充当HTTP客户端和HTTP服务器,但如果它发出GET请求,它就是一个客户端。它可以向它发出的请求添加它想要的任何头。在HTTP请求中添加
内容处置
头仍然没有意义。客户端无法控制生成响应的服务器向该响应添加的头。