dqysi86208 2019-03-04 13:21
浏览 51

将文件和文本从nodejs服务器发布到php服务器

I'm trying to send a file from nodejs using http post options to php server and when I'm using postman to post that file this is an image for postman:

enter image description here

when I post data (file and text) directly from postman to php server through this php code:

<?php
print_r($_FILES );
print_r($_REQUEST );
?>

I get the output like image above

but when I post the data from my nodejs server with this code:

class of http options:

export const postOptions: PostOptions = {
  port: 80,
  hostname: "127.0.0.1",
  path: "/load.php",
  method: "POST",
  headers: {
    "Content-Type": "multipart/form-data"
  }

and this is the code of post request:

const objstatic = JSON.stringify({
      uid: "yghu",
      docfile: imageFile,
      name: "554",
      subRAId: "554"
    });
    const req = http.request(postOptions, res => {
      console.log(`statusCode: ${res.statusCode}`);
      res.on("data", d => {
        process.stdout.write("----->" + d);
      });
    });
    req.on("error", error => {
      console.error(error);
    });
    req.write(objstatic);
    req.end();

I got empty arrays:

Array(
)

Array(
)

so how post file and text from nodejs server to php server note: I have control over two servers

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 帮我写一个c++工程
    • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
    • ¥15 关于smbclient 库的使用
    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教