首页 > 解决方案 > C# Form app:使用HttpClient从磁盘上传xml文件,NodeJS服务器:正确接收xml文件

问题描述

在我的 C# Win Form 应用程序中,我可以上传这样的 xml 文件,使用 HttpClient 非常清晰和简单:

var uri = http://localhost:3000/uploads
XmlDocument xDoc = new XmlDocument();
xDoc.Load(xml file on disk);
HttpClient client = new HttpClient();
HttpContent content = new StringContent(xDoc.InnerXml, Encoding.UTF8, "text/xml");
HttpResponseMessage result = client.PostAsync(uri, content).Result;

但是,在服务器端(在 NodeJS/Express 中),我如何接收它?我来了:

const express = require('express');
const app = express();
app.post('/uploads', async function (req, res) {

await receive_xmlfile(req.body).then ((result) => {
    response(res, result);
}).catch(error => {
    sendError(res);
    log_exception(error, req);
   });
});

在这里感觉很“迷失”。我想使用一些函数(receive_xmlfile),但首先如何获取 xml?应该在体内?感谢任何答案。

标签: c#node.jsexpresshttpclient

解决方案


推荐阅读