When using the httpwebrequest connection web service, the error of "unable to establish a connection because the target computer actively rejected it" is very frustrating. The root cause of this problem is essential for solving it.
Error reason:
This error message indicates that the server machine exists, but it does not listen to any services on the designated port, or the firewall prevents the connection attempt. Or, if the error intermittent appears, it may indicate that the server's request queue is full.
Request queue and retry:
When the client tries to connect to the server, if the server cannot handle the request immediately, they will be discharged into the request queue. The request queue has a limited capacity and is usually set to smaller numbers. If the request queue is full, the client will receive an error that "target computer actively rejected it". In order to solve this problem, the retry logic should be achieved in the client code to deal with these temporary connections.
Server configuration:
If the problem of the request queue continues, it may indicate that the server configuration is wrong. You can adjust the request queue settings in the server configuration file or through its management tools to increase the number of queuing requests.
The server processing load is too heavy:
The server -side processing request sometimes consumes a lot of resources, resulting in accepting new connection delays. In order to reduce this situation, consider moving the heavy processing tasks to a separate work thread, so as to release the main acceptance cycle to process the transmission connection.
Summary:
To solve the "target computer actively rejected it" error requires a thorough check of the configuration of the server, request queue and processing performance. To achieve retry logic in the client code and adjust the server settings accordingly, the problem can alleviate this problem.
The above is the detailed content of Why Does My HttpWebRequest Fail with 'Target Machine Actively Refused It'?. For more information, please follow other related articles on the PHP Chinese website!