Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failing to send HTTP/1.0 POST request #385

Open
yashp5 opened this issue May 14, 2021 · 1 comment
Open

Failing to send HTTP/1.0 POST request #385

yashp5 opened this issue May 14, 2021 · 1 comment

Comments

@yashp5
Copy link

yashp5 commented May 14, 2021

Failing to send a HTTP/1.0 post request. Getting the following error.

TypeError [ERR_INVALID_PROTOCOL]: Protocol "http:" not supported. Expected "https:"
    at new NodeError (node:internal/errors:329:5)
    at new ClientRequest (node:_http_client:168:11)
    at Object.request (node:http:52:10)
    at /Users/yash/elocity/utilityportal-backend/src/ocpp/command/CommandStateManager.ts:167:43
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:94:5) {
  code: 'ERR_INVALID_PROTOCOL'
}

Configuration of the agent and http request client:

const agentConfig = {
	host: domain,
	port: Number.isNaN(port) ? 80 : +port,
	spdy: {
		protocols: ["http/1.0"],
		ssl: false
	},
};
const agent = spdy.createAgent(agentConfig);
const httpOptions = {
	agent,
	method: "POST",
	path,
	headers: {
		"Content-Type": "application/xml",
		"Content-Length": Buffer.byteLength(client.lastRequest),
	},
	protocol: "http:",
	port: Number.isNaN(port) ? 80 : +port,
};
const post_req = http.request(httpOptions, function (res) {
	res.setEncoding("utf8");
	var result = "";
	res.on("data", function (chunk) {
		result += chunk;
	});
	res.on("end", function () {
		console.log(result);
	});
});
post_req.removeHeader("Transfer-Encoding");
post_req.on("error", function (err) {
	console.log(err);
});
post_req.write(client.lastRequest);
post_req.end();
})

I am not really familiar with making HTTP/1.0 request so any help regarding this would be greatly appreciated.

@lamweili
Copy link

Add the plain options.

const agentConfig = {
	host: domain,
	port: Number.isNaN(port) ? 80 : +port,
	spdy: {
		protocols: ["http/1.0"],
+               plain: true, 
		ssl: false
	},
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants