Unable to send empty post request
I need to send a Post request without body. Also, need to not include content-type header. I can't do that because I am getting "Operation was aborted by an application callback" error when I am trying to not use POSTFIELDS. If I use POSTFIELDS as an empty string, then the content-type is set up by default, and I can't prevent it. I tried both curly and Curl. Any ideas how I could achieve this with node-libcurl? It works OK with curl itself: I was able to send a request without body and without any content-type.
This is an example with Curl
import { Curl, curly } from "node-libcurl";
const curl = new Curl();
curl.setOpt(Curl.option.VERBOSE, true);
curl.setOpt(Curl.option.USERAGENT, "myuseragent");
curl.setOpt(Curl.option.DEFAULT_PROTOCOL, "https");
curl.setOpt(Curl.option.PATH_AS_IS, true);
curl.setOpt(Curl.option.URL, "yahoo.com");
curl.setOpt(Curl.option.FOLLOWLOCATION, true);
curl.setOpt(Curl.option.POSTREDIR, 0);
curl.setOpt(Curl.option.MAXREDIRS, 10);
curl.setOpt(Curl.option.POST, 1);
curl.on("end", function (statusCode, body, headers) {
console.log(statusCode);
this.close();
});
curl.on("error", function (error) {
console.log(error);
this.close();
});
curl.perform();
when using the CLI, what is the command you are using?
when using the CLI, what is the command you are using?
curl 'https://gateway-run.bls.dev/api/v1/nodes/someid/start-session'
-X 'POST'
-H 'accept: /'
-H 'accept-language: en-US,en;q=0.9,ru;q=0.8,ka;q=0.7'
-H 'authorization: Bearer some-token'
-H 'content-length: 0'
-H 'origin: chrome-extension://pljbjcehnhcnofmkdbjolghdcjnmekia'
-H 'priority: u=1, i'
-H 'sec-fetch-dest: empty'
-H 'sec-fetch-mode: cors'
-H 'sec-fetch-site: cross-site'
-H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36'
-H 'x-extension-version: 0.1.7'
I am experiencing this as well
A way to do this is to delete the Content-Type added by libcurl by providing an empty value for it through HTTPHEADER and the error being reported is due to not providing a READFUNCTION with a POST request. You can simply set it to a function that does not write any bytes:
curl.setOpt(Curl.option.HTTPHEADER, ['Content-Type:'])
curl.setOpt(Curl.option.READFUNCTION, () => {
return 0
})