-
Notifications
You must be signed in to change notification settings - Fork 132
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
POST not working? #6
Comments
Hi don't know I'll take a look. Thanks. |
Hi again Could you please send me the code (or similar code ...) your using with the POST method? thanks in advance. |
Please take a look at my pull request, I am guessing since Content-Length header wasn't being sent, express might be thinking that the request came with an empty body |
fix it with pull request #8 Thanks. |
Still not working for me. See this https://gist.github.com/TobyEalden/6192116 Also, the recent pull request introduced a bug whereby args.headers is mandatory - if this line https://gist.github.com/TobyEalden/6192116#file-test-js-L7 is missing there is a crash. |
yep, you're Right I've just pushed the fix for the headers issue. I'm going to test your code and see if I can find what happends Thanks |
Hi I've been trying with my own server (simple node.js server without using "express.js") and everything works fine. please see https://gist.github.com/aacerox/f2fdf78e651804e5b004. It seems to be something in the way express manage requests. Maybe you can use a node debugger like https://github.com/node-inspector/node-inspector to debug what's "express.js" doing with requests. by the way you can enable console debug on node-rest-client by setting an environtment variable DEBUG like: windows -> set DEBUG=true I'll try to see something by my self. |
I've found it!!! you must set Content-type:application/json in client params headers: var restClient = require("../../lib/node-rest-client").Client;
var appgAPIClient = new restClient();
var apiURLBase = "http://localhost:5000";
var args = {
data: { test: "hello" },
headers:{"Content-Type": "application/json"}
};
appgAPIClient.post(apiURLBase + "/postTest", args, function(data,response) {
if (data.hasOwnProperty("ok") && data.ok === true) {
console.log("success");
} else {
console.log("failure");
}
}); Also I've a bug in my last commit with header initialization, that I've already fix. |
Great thanks - I can confirm that works for me too. BTW strictly speaking, https://github.com/aacerox/node-rest-client/blob/master/lib/node-rest-client.js#L149 should be
:) Thanks for your help |
Hi
I'm having trouble getting POST methods to work - the request arrives at my API, but the req.body element is an empty object (even though I have specified args.data). GET works fine.
I tried with both direct and registered methods.
My API is implemented using express and is currently running on localhost:5000. The API works if I use an HTML form to post...
Any ideas what I might be missing?
Thanks,
Toby
The text was updated successfully, but these errors were encountered: