Use http proxy, Java solve the problem of foreign requests to be fixed ip

Background: The docking third-party interfaces, third-party security reasons, needs to be fixed ip whitelist. Foreign companies use dynamic ip.

Method:

1. buy a fixed ip of the server, such as cloud virtual servers. Http proxy server set up, such as prioxy.

2. Install the agent software Privoxy

yum install -y epel-release privoxy

Edit / etc / privoxy / config file

Modify the binding address, search listen-address, need to modify bound IP

listen-address  0.0.0.0:8118

Set enable-remote-toggle 1

enable-remote-toggle 1

Restart Service

service privoxy restart

Check the service status

[root@localhost ~]# service privoxy status
Redirecting to /bin/systemctl status privoxy.service
● privoxy.service - Privoxy Web Proxy With Advanced Filtering Capabilities
   Loaded: loaded (/usr/lib/systemd/system/privoxy.service; disabled; vendor preset: disabled)
   Active: active (running) since Wed 2020-03-04 17:38:26 CST; 5s ago
  Process: 23138 ExecStart=/usr/sbin/privoxy --pidfile /run/privoxy.pid --user privoxy /etc/privoxy/config (code=exited, status=0/SUCCESS)
 Main PID: 23139 (privoxy)
   Memory: 872.0K
   CGroup: /system.slice/privoxy.service
           └─23139 /usr/sbin/privoxy --pidfile /run/privoxy.pid --user privox...

Mar 04 17:38:25 localhost.localdomain systemd[1]: Starting Privoxy Web Proxy ...
Mar 04 17:38:26 localhost.localdomain systemd[1]: Started Privoxy Web Proxy W...
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost ~]# netstat -anop | grep 8118
tcp        0      0 0.0.0.0:8118            0.0.0.0:*               LISTEN      23139/privoxy        off (0.00/0/0)
tcp        0      0 172.16.1.120:8311       172.16.1.123:28118      ESTABLISHED 15519/nginx: worker  off (0.00/0/0)

 

ps:

https://www.cnblogs.com/hongdada/p/10787924.html

https://blog.csdn.net/Drug_/article/details/88067231

https://www.jianshu.com/p/05ac5d0911cc

 

3.HttpClient proxy settings

HttpPost = HttpPost new new HttpPost (URL);
 // Set the IP proxy, connection time is provided, read the data setting request timeout, the timeout setting acquisition Connection Manager Connect, 
HttpHost Proxy = new new HttpHost ( "172.16.1.120", 8118 ); 
requestConfig requestConfig = RequestConfig.custom () 
    .setProxy (Proxy) 
    .setConnectTimeout ( 10000 ) 
    .setSocketTimeout ( 10000 ) 
    .setConnectionRequestTimeout ( 3000 ) 
    .build (); 
httpPost.setConfig (requestConfig);

 

If you are unable to modify the jar, local how to debug?

 

Find the target source code, create a directory under the project code and object code as a package, and a new class file of the same name, a copy of the target class code to the new file, and then the corresponding proxy settings.

The principle is the code loaded only once, who is who is the most priority loads, in order to achieve code coverage.

Note: Local development and debugging is completed, remove the cover of this document.

 

Guess you like

Origin www.cnblogs.com/phpdragon/p/12410858.html