Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simulate a POST request

I am developing a node.js app using express. I'm listening on port 3000 of localhost for POST requests. The only way I know how to simulate a POST request is using jQuery.ajax():

$.ajax({
    url: 'localhost:3000',
    type: 'POST',
    data: {hello: 1},
    success: function (data) {
        console.log(data);
    },
    error: function (data) {
        console.log(data);
    }
});

Unfortunately, I get a the error message:

"XMLHttpRequest cannot load localhost:3000. Cross origin requests are only supported for HTTP."

What am I doing stupidly? Is there a better approach I should consider?

like image 942
Randomblue Avatar asked Apr 15 '26 18:04

Randomblue


1 Answers

You can also use unix command curl to simulate the requests. With it you get horde of options.

In your case it would be curl http://localhost:3000 -d "{hello:1}" -X POST

like image 75
Samyak Bhuta Avatar answered Apr 18 '26 07:04

Samyak Bhuta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!