Solution to socket hang up error in Nodejs Post request, nodejshang

Source: Internet
Author: User

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...


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.