美文网首页
axios 发送post请求

axios 发送post请求

作者: 一只肥豚鼠 | 来源:发表于2019-02-15 19:16 被阅读0次

方案一

在node中使用axios以post的方式发送一张图片给某个server时:

let data = fs.createReadStream(__dirname + '/test.jpg')
        axios.post(url,{media:data,type:"image"})
        .then(function (response) {
        console.log(response.data);
        })
        .catch(function (error) {
        console.log(error);
        })

方案二

事实证明,这样做是完全没有用的,我尝试向另一个服务器poststream,返回的总是错误。然而,如果我使用request,下面这样的代码是完全没有问题的:

let data = fs.createReadStream(__dirname + '/test.jpg')
let form = {
type:"image",
media:data
}
request.post({url:url,formData:form},(err,res,body)=>{
if(err) console.log(err)
console.log(body)
})
// 注册事件方法
    register: function() {
      let registerUrl = this.GetServerUrl() + "/user/signup";
      let params = {
        username: this.username,
        password: this.password,
        email:    this.email,
        captcha:  this.captcha
      };
      this.axios
        .post(registerUrl, params)
        .then(response => {
          if(response.status == 0) {
            
          }
        });
    }

相关文章

  • axios

    axios axios 是一个专注于网络请求的库! axios 的基本使用:繁 发送get请求: 发送post请求...

  • vue发送post请求

    模拟vue结合axios发送post请求

  • axios

    全局配置 axios发送get请求 发送post请求 参考文档 看云npm

  • vue基础知识面试题(二)

    ref获取元素的内容: axios发送get请求: 挂载公共请求头 axios的get请求和post请求:

  • Axios里POST application/x-www-for

    axios发起post请求,后台需要form表单形式,按照文档发送post请求,但是发送数据变成字符串形式,后面还...

  • axios 发送post请求

    方案一 在node中使用axios以post的方式发送一张图片给某个server时: 方案二 事实证明,这样做是完...

  • Vue axios 403

    前端是vue2.0,网络请求用的是axios,后端是springboot2.0 用axios向后端发送post请求...

  • vue + axios发送post请求,403错误的解决

    前端是vue2.0,网络请求用的是axios,后端是springboot2.0 用axios向后端发送post请求...

  • vue + axios发送post请求,403错误的解决

    前端是vue2.0,网络请求用的是axios,后端是springboot2.0用axios向后端发送post请求,...

  • vue -- 网络应用 -- axios

    axios 网络请求库 axios必须先导入后使用 使用get或post方法即可发送对应的请求 then方法中的回...

网友评论

      本文标题:axios 发送post请求

      本文链接:https://www.haomeiwen.com/subject/zcwmeqtx.html