Article Catalog
preamble
Front-end separation project, in the call interface debugging, we can
cpolar intranet penetration will be the local server-side interface simulation of the public network environment remote call debugging, this tutorial we Java server-side interface as an example.
1. Local environment setup
1.1 Environmental parameters
- JDK1.8
- IDEA
- SpringBoot
- Maven
- Tomcat9.0
- Postman
1.2 Build springboot service project
build a springboot service project, write an interface, in order to better visualize, here to create a pos request interface
@RestController
@RequestMapping("/test")
public class InterfaceTest {
/**
* :: Testing of interfaces
* @param data
* @return Map<String,String>
*/
@PostMapping("/interTest")
public Map<String,String>interTest(@RequestBody Map<String,String> data){
System.out.println(data);
if (data.size()>0){
return data;
}
data.put("code","404");
return data;
}
}
2. Intranet penetration
Here we use cpolar for intranet penetration, supports
http/https/tcp protocols, unlimited traffic, no need for a public IP, no need to set up a router, easy to use.
2.1 Installing and configuring cpolar intranet penetration
cpolar official website:https://www.cpolar.com/
2.1.1 windows
After entering the cpolar official website, download the windows version version, double click the installation package all the way to the default installation.
2.1.2 linux
- cpolar installation (for domestic use)
curl -L https://www.cpolar.com/static/downloads/install-release-cpolar.sh | sudo bash
- or cpolar short link installation method: (for foreign use)
curl -sL https://git.io/cpolar | sudo bash
- Check the version number, there is a normal display of the version number that is successfully installed
cpolar version
Log in to the backend of the cpolar website, click on Authentication on the left side, check your authentication token, and after that paste the token in the command line
cpolar authtoken xxxxxxx
cpolar http 8080
Press ctrl+c to exit
- Adding services to the system
sudo systemctl enable cpolar
sudo systemctl start cpolar
2.2 Creating a Tunnel to Map Local Ports
After cpolar is successfully installed, access local port 9200 on your browser [
http://localhost:9200], log in using the cpolar account.
![Remote debugging with springboot server-side? Try HTTP for service listening Remote debugging with springboot server-side? Try HTTP for service listening](https://imgs.developpile.com/imgs/860047544969ee14237e3d57a94c5d43.png)
Click Tunnel Management – Create Tunnel on the left dashboard to create a tomcat port 8080 http tunnel
- Tunnel name: can be customized, be careful not to duplicate the existing tunnel name.
- Protocol: choose http
- Local address: 8080
- Domain Type: Free random domain name selection
- Region: Select China vip
strike (on the keyboard)
establish
![Remote debugging with springboot server-side? Try HTTP for service listening Remote debugging with springboot server-side? Try HTTP for service listening](https://imgs.developpile.com/imgs/c60b2b08aac03aea044423f59c667d4c.png)
After the tunnel is successfully created, click Status – Online Tunnel List on the left to view the generated public address, and then copy the address.
2.3 Testing public network addresses
Here to Postman interface debugging tool to send requests to the interface, in postman to create a post request method. Enter the public address of the copy plus the path to the interface, use JSON format for the parameters, set the parameters and click the
![Remote debugging with springboot server-side? Try HTTP for service listening Remote debugging with springboot server-side? Try HTTP for service listening](https://imgs.developpile.com/imgs/20650ddaa502f5ed825d8b37b1ce1011.png)
Debugging interface debugging interface in the service interface to see whether the request to enter the interface, into the interface that the call is successful
3. Fixed public network address
Since the above tunnel created using cpolar uses a random public address that changes randomly within 24 hours, it is not conducive to long-term remote access. Therefore, we can configure a second-level subdomain for it, which is a fixed address that does not change randomly
Note that you need to upgrade the cpolar package to the basic package or above, and each package corresponds to a different bandwidth. [cpolar.cn has been filed].
3.1 Reservation of a second-level subdomain
Login to cpolar official website, click on the left side of the reservation, choose to reserve a second-level sub-domain, set a second-level sub-domain name, click on the reservation, after the reservation is successful, copy the name of the reserved second-level sub-domain.
3.2 Configuring second-level subdomains
interviews
http://127.0.0.1:9200/To configure a tunnel, log into the cpolar web UI management interface, click Tunnel Management – Tunnel List on the left dashboard, find the 8080 tunnel you want to configure, and click Edit on the right side.
![Remote debugging with springboot server-side? Try HTTP for service listening Remote debugging with springboot server-side? Try HTTP for service listening](https://imgs.developpile.com/imgs/70a50dff15bc61c6b7bdc47dddcc8542.png)
Modify the tunnel information to configure a successfully reserved second-level subdomain into the tunnel
- Domain type: select a second-level subdomain
- Sub Domain: Fill in the second-level sub domain name of the successful reservation, in this case, test01.
strike (on the keyboard)
update
![Remote debugging with springboot server-side? Try HTTP for service listening Remote debugging with springboot server-side? Try HTTP for service listening](https://imgs.developpile.com/imgs/a8bf35f2cf0c0252e2bedb2118f8524a.png)
After the update is complete, open the list of online tunnels, you can see that the public address has changed, the address name has also changed to the name of the reserved second-level sub-domain, copy it down!
3.2 Testing the use of a fixed public address
Open postman, and call it with a fixed http address.
![Remote debugging with springboot server-side? Try HTTP for service listening Remote debugging with springboot server-side? Try HTTP for service listening](https://imgs.developpile.com/imgs/50518f854a2215ccd0067e428dc04be1.png)
The same server-side debugging debugging to see if the request to enter the interface, into the interface that success!
4. Cpolar listener
We can also use the cpolar listener (
http://localhost:4040) View the interface request logs to deal with a nasty bug. or even replay the request message packet to speed up the request for testing. click the Replay button to resend that HTTP signaling request instead of manually re-triggering the operation. The following describes listening to requests using the cpolar listener.
4.1 Enabling Listening
Select the http tunnel we just created and configured and click on the right side of the
compiler
![Remote debugging with springboot server-side? Try HTTP for service listening Remote debugging with springboot server-side? Try HTTP for service listening](https://imgs.developpile.com/imgs/ea7231d30368cf47043b3ac6d4c6080b.png)
Open the advanced settings and turn on listening.
4.2 Request listening
accessing local port 4040 in a browser.
http://localhost:4040
![Remote debugging with springboot server-side? Try HTTP for service listening Remote debugging with springboot server-side? Try HTTP for service listening](https://imgs.developpile.com/imgs/372e34870723627ba2699c2428cda6e5.png)
After sending a request to the server , here will display the relevant request log , you can see the request mode , the requested data , interface path , and return status and results , greatly improving the debugging efficiency .
Reprinted from the cpolar intranet penetration article:Springboot server-side interface public network remote debugging, and the implementation of HTTP service listener