Reputation: 116343
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?
Upvotes: 3
Views: 2826
Reputation: 1254
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
Upvotes: 3
Reputation: 196187
Use http://localhost:3000
for the url... otherwise it gets used as a directory or file
Upvotes: 2