Solution to socket hang up error in Nodejs Post request, nodejshang
Refer to the method used to send an http post request on the official node. js website to simulate post submission. The socket hang up error is reported in actual use.
Later, it was found that the request header was set. The headers field information must be added to the sending options (this estimation is also related to the server of the other party. For Incomplete post request headers, may be discarded ).
The complete code is as follows (if you encounter a type problem, you can make a reference ):
Copy codeThe Code is as follows:
Var querystring = require ('querystring ')
, Http = require ('http ');
Var data = querystring. stringify ({
Info: 'hi ',
Test: 5
});
Var opt = {
Hostname: 'www .test.com ',
Port: 9094,
Path: '/perationsqlquery ',
Method: 'post ',
Headers :{
'Content-type': 'application/x-www-form-urlencoded ',
'Content-length': data. Length
}
};
Var req = http. request (opt, function (res ){
Res. on ('data', function (data ){
Console. log (data. toString ());
});
});
Req. on ('error', function (e ){
Console. log ('problem with request: '+ e. message );
});
Req. write (data );
Req. end ();
Nodejs and socketio are always disconnected automatically?
Debug the server. You haven't seen the problem of timeout. after I received the call, I sent a few requests and then the connection was disconnected. only the debugging-fired close timeout for client can be refreshed.
Help nodejs and socketio Problems
I don't understand what you mean...
"Successfully received messages", meaning:
Socket. on ('recemsg ', function (data) {// console. log (data); <= is there a value here? Your client didn't respond, doesn't it mean you didn't see the effect?
If so .................................
Put the client code at the end, that is, before </body> or put the client code into $ (function (){});
Or asynchronous loading ................................
If it still doesn't work, you can't...