Node-RED http-request节点Base64加密基础认证问题求助
Hey there! I’ve run into this exact problem before, so let’s break down what’s going on and how to fix it.
First, let’s clarify: normally, when you check "Use basic authentication" in the http-request node and enter your username/password, Node-RED should automatically encode them into the Base64 string needed for the Authorization header. But if that’s not working for your target server, here are two reliable solutions:
1. Double-Check Your Node Configuration & Deployment
It sounds obvious, but it’s easy to miss:
- Make sure you’ve actually checked the "Use basic authentication" box in the http-request node’s settings, and filled in the correct username and password.
- After making changes, click the Deploy button in the top-right corner of the Node-RED editor. If you skip this, your old (broken) configuration will keep running.
2. Manually Construct the Authorization Header
If the node’s automatic encoding isn’t playing nice with your server (some servers have strict formatting requirements), you can replicate the exact working command-line behavior by building the header yourself:
- Add a Function node right before your http-request node.
- Paste this code into the Function node (replace
your_usernameandyour_passwordwith your actual credentials):
// Replace with your actual credentials const username = "your_username"; const password = "your_password"; // Build the Basic Auth string and encode it to Base64 const authCredentials = `${username}:${password}`; const base64Auth = Buffer.from(authCredentials).toString('base64'); // Add the Authorization header to the message msg.headers = msg.headers || {}; msg.headers.Authorization = `Basic ${base64Auth}`; return msg;
- Go back to your http-request node and uncheck the "Use basic authentication" option (this prevents conflicting headers from being sent).
- Deploy your flow and test the request again. This should match exactly what you did in the command line, so it should work.
The reason your command-line test worked is because you manually handled the Base64 encoding—this method replicates that exact logic, bypassing any potential quirks in the node’s automatic handling.
内容的提问来源于stack exchange,提问作者Urs Klas

