有没有办法进行休息调用,需要通过Node.js进行身份验证的客户端证书?
我想测试REST API如何处理具有无效JSON语法的主体的POST请求,例如缺少逗号.我正在使用node.js编写API测试.我正在使用frisby,但我也尝试了超级.没运气.使用以前的工具,您将请求主体作为JavaScript对象传递,因此不行.我还尝试将无效的JSON作为字符串传递而没有任何运气,因为字符串也是有效的JSON(下面的示例).有任何想法吗?
frisby.create('Ensure response has right status')
.post('http://example.com/api/books', '{"invalid"}', {json: true})
.expectStatus(400)
.toss();
Run Code Online (Sandbox Code Playgroud) 我在使用node.js发布数据时遇到问题 Content-type: 'application/x-www-form-urlencoded'
var loginArgs = {
data: 'username="xyzzzzz"&"password="abc12345#"',
//data: {
// 'username': "xyzzzzz",
// 'password': "abc12345#",
//},
headers: {
'User-Agent': 'MYAPI',
'Accept': 'application/json',
'Content-Type':'application/x-www-form-urlencoded'
}
};
Run Code Online (Sandbox Code Playgroud)
并且发布请求是:
client.post("http:/url/rest/login", loginArgs, function(data, response){
console.log(loginArgs);
if (response.statusCode == 200) {
console.log('succesfully logged in, session:', data.msg);
}
Run Code Online (Sandbox Code Playgroud)
它总是返回用户名/密码不正确.
在其余的api中,据说请求体应该是:
username='provide user name in url encoded
format'&password= "provide password in url encoded format'
Run Code Online (Sandbox Code Playgroud) var https = require('https');
var p = '/api/username/FA/AA?ZOHO_ACTION=EXPORT&ZOHO_OUTPUT_FORMAT=JSON&ZOHO_ERROR_FORMAT=JSON&ZOHO_API_KEY=dummy1234&ticket=dummy9876&ZOHO_API_VERSION=1.0';
var https = require('https');
var options = {
host: 'reportsapi.zoho.com',
port: 443,
path: p,
method: 'POST'
};
var req = https.request(options, function(res) {
console.log("statusCode: ", res.statusCode);
console.log("headers: ", res.headers);
res.on('data', function(d) {
process.stdout.write(d);
});
});
req.end();
req.on('error', function(e) {
console.error(e);
});
Run Code Online (Sandbox Code Playgroud)
当我运行上面的代码时,我得到以下错误.
错误信息:
statusCode: 411
headers: { 'content-type': 'text/html',
'content-length': '357',
connection: 'close',
date: 'Thu, 24 Nov 2011 19:58:51 GMT',
server: 'ZGS',
'strict-transport-security': 'max-age=604800' }
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
411 - Length Required
Run Code Online (Sandbox Code Playgroud)
如何修复abobe错误?
我试过在下面做 …
为什么在 Node.js v18.4.0 中运行此代码时出现请求不受支持的错误,但在 v16.16.0 中却成功?
返回错误的直接代码是我为公司内部制作的库的单元测试。请原谅代码中的一些排除,但我已尝试尽可能地整理它以便公开发布。
// ~/http/tests/Client.spec.ts
import { HttpClient } from '../src';
describe('Standard HTTP Client', () => {
const { request: http } = HttpClient;
it('should save the response when a state is given', async () => {
const response = await http({ method: 'GET', url: 'https://www.google.com' });
expect(response).toBeDefined();
});
});
Run Code Online (Sandbox Code Playgroud)
v16中的结果是成功的,但v18中的结果是:
Error: unsupported
at configSecureContext (node:internal/tls/secure-context:282:15)
at Object.createSecureContext (node:_tls_common:117:3)
at Object.connect (node:_tls_wrap:1624:48)
at Agent.createConnection (node:https:150:22)
at Agent.createSocket (node:_http_agent:346:26)
at Agent.addRequest (node:_http_agent:297:10)
at new ClientRequest …Run Code Online (Sandbox Code Playgroud) 我正在开发需要与Google进行身份验证的节点应用程序。当我请求令牌时,https://accounts.google.com/o/oauth2/token会回复:
error: 400
{
"error" : "invalid_request"
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试过在curl中发出相同的请求,并且收到了相同的错误,所以我怀疑我的请求有问题,但是我不知道是什么。我在下面粘贴了我的代码:
var request = require('request');
var token_request='code='+req['query']['code']+
'&client_id={client id}'+
'&client_secret={client secret}'+
'&redirect_uri=http%3A%2F%2Fmassiveboom.com:3000'+
'&grant_type=authorization_code';
request(
{ method: 'POST',
uri:'https://accounts.google.com/o/oauth2/token',
body: token_request
},
function (error, response, body) {
if(response.statusCode == 201){
console.log('document fetched');
console.log(body);
} else {
console.log('error: '+ response.statusCode);
console.log(body);
}
});
Run Code Online (Sandbox Code Playgroud)
我已三重检查以确保我提交的所有数据都是正确的,并且仍然出现相同的错误。我该怎么做才能进一步调试呢?
我正在使用Node.js,我需要将包含特定数据的POST请求发送到外部服务器.我正在使用GET做同样的事情,但这更容易,因为我不必包含额外的数据.所以,我的工作GET请求如下:
var options = {
hostname: 'internetofthings.ibmcloud.com',
port: 443,
path: '/api/devices',
method: 'GET',
auth: username + ':' + password
};
https.request(options, function(response) {
...
});
Run Code Online (Sandbox Code Playgroud)
所以我想知道如何用POST请求做同样的事情,包括如下数据:
type: deviceType,
id: deviceId,
metadata: {
address: {
number: deviceNumber,
street: deviceStreet
}
}
Run Code Online (Sandbox Code Playgroud)
谁能告诉我如何将这些数据包含在上面的选项中?提前致谢!
我对AWS lambda函数和nodejs相对较新。我正在尝试通过此网站上的HTTP POST请求获取一个国家的5个城市的列表:“ http://www.webservicex.net/globalweather.asmx?op=GetCitiesByCountry ”
我一直在寻找如何在lambda函数中执行HTTP POST请求,但似乎找不到很好的解释。
我为http帖子找到的搜索:
https://www.npmjs.com/package/http-post 如何在node.js中发出HTTP POST请求?
javascript lambda amazon-web-services node.js alexa-skills-kit
我有一个在端口 3000 和 4000 上运行的 Express js 服务器\n并且想要从服务器 3000 向服务器 4000 发送 post 请求
\n\n我试过这个:
\n\nvar post_options = {\n url: "http://172.28.49.9:4000/quizResponse",\n timeout: 20000,\n method:"POST",\n encoding: "application/json; charset=utf-8",\n body : {data: formdata}\n};\nrequest(post_options,\nfunction optionalCallback(err, httpResponse, body) {\n if (err) {\n console.log(err);\n }else\n console.log(body);\n});\nRun Code Online (Sandbox Code Playgroud)\n\n但出现此错误:
\n\n\n\n\n类型错误:第一个参数必须是 Request.write 处 ClientRequest.OutgoingMessage.write (_http_outgoing.js:456:11) 处的字符串或缓冲区 (D:\\restfullApi\\examineerapi\\node_modules\\request\\request.js\ xe2\x80\x8c\xe2\x80\x8b:1514:27) 在末尾 (D:\\restfullApi\\examineerapi\\node_modules\\request\\request.js\xe2\x80\x8c\xe2\x80\x8b :552:18) 立即。(D:\\restfullApi\\examineerapi\\node_modules\\request\\request.js\xe2\x80\x8c\xe2\x80\x8b:581:7) 在 runCallback (timers.js:637:20) 在 tryOnImmediate (timers.js:610:5) 在 processImmediate [as _immediateCallback] (timers.js:582:5)
\n
这并不像我想象的那样工作。请帮我解决这个问题。
\nnode.js ×9
javascript ×5
request ×3
post ×2
rest ×2
certificate ×1
express ×1
frisby.js ×1
google-api ×1
http ×1
json ×1
lambda ×1
oauth ×1
oauth-2.0 ×1
superagent ×1
typescript ×1