node.js - When running http requests in nodejs to test my rest api it stops, why? -
I have an other API that is now fully working and now it is going to be manually tested with postmen Instead of operating CRAD I I know of a truth that all requests are working because I am given a status code of 200.
My problem is when the test command line moves, it will show that it ran through almost everyone but it will not go beyond some of GET requests (even if I have the same type of requests The first code in the code is.
When I comment on the GET request where it gets stuck, then there are no problems running requests.
GET ME The code for requests is:
var option = {Ho : 'Localhost', Port: 4000, Path: '/ Api / services / 00001 / method / 01 / args / 01'}; http.get (option, function) {console.log ("Received response:" + Res.statusCode + "\ nGET logic user 01 00001 for method 01. \ n \ n");}) ('error', function (e) {console.log ("error found:" + e.message );}); Am I missing something which can sometimes get the code to stop running? Any help is appreciated.
I can add code for my other actions as well as if necessary Then (post, put, delayed).
After running my whole code, nothing was understood, I realized that it stops in my second delete request, the code is as follows: < / P>
var options = {host: 'localhost', port: 4000, path: '/ api / services / 00001 / method / 01', method: 'DELETE'}; Http.get (options, function (res) {console.log ("Understand:" + res.statusCode + "\ nDELETE method 01 for user 00001. \ n \ n");}). ('Error', function (e) {console.log ("error found:" + e.message);});
The solution can be either one or both:
-
Setting
agent: incorrectin your requestoptions. This prevents the request from using a global HTTP agent socket pool, which means that the request will receive its new socket each time. I've seen strange things, where nodes are the HTC never start Agent request execution is ongoing under the one thing that you know that your OS user (file processor) file descriptor limits. If you make multiple concurrent requests usingagent: false, then you may need an OS limit. -
Use Res.resume ()to remove any response data from the callback server in your request whenever you do not care about it By doing so, it can be ensured that the socket from the HTC agent socket pool is available for another request.
Comments
Post a Comment