node.js - NodeJS 使用 absoluteURI 发送 http 请求
问题描述
我正在使用一个奇怪的 HTTP 服务器,它只接受 HTTP 请求,如下所示:
GET http://10.0.0.1/test
Host: 10.0.0.1
Cache-Control: no cache
Connection: Keep-Alive
在路径中添加“http://”节点
当我发送 HTTP 请求(使用底部的代码)时,请求如下所示:
GET /test
Host: 10.0.0.1
Cache-Control: no cache
Connection: Keep-Alive
代码示例:
var request = require('request');
var options = {
'method': 'GET',
'uri': 'http://10.0.0.1/test',
'headers': {
'Host': '10.0.0,1',
'Cache-Control': 'no cache',
'Connection': 'Keep-Alive'
}
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
知道如何像服务器期望的那样使用标准库发送请求吗?
解决方案
推荐阅读
- python - 为什么 python 中的 .Shape 属性总是在它的索引中具有 [0] 。如果可能,请用外行的方式解释
- python - 将缺少 x 值的图组合起来
- visual-studio-code - Visual Studio 代码编辑器中的编辑器组缺口
- c# - 使用实体框架、Lambda 表达式和存储库模式从多个表中搜索数据
- java - 如何从 ABC.jar 文件调用 libXYZ.so 的 API
- microservices - 平均响应时间与平均周转时间 (DIN_IEC_25023) 差异?
- c# - 在 ASP.NET Blazor 中获取和发布
- firebase - Firebase 身份验证暂存环境
- .net - .Net 项目的 SonarQube 模板
- javascript - 如何使用按钮关闭表单