Front-end and back-end joint debugging to solve the cross-domain problem of URL as a parameter

During the front-end and back-end joint debugging, the URL is passed as a parameter to the back-end, and the result is a problem. The reason is that when the request is sent, the browser will resolve the two domain names from the correct request, so when it comes to the back-end, there will be a cross Domain issues, as for what is cross-domain, please refer to https://www.jianshu.com/p/f049ac7e2220

Solution

method one:

Encode the url that the front end needs as a parameter, as shown in the following code

  urls : encodeURIComponent(encodeURIComponent("https://blog.csdn.net")),

The back-end decodes the passed code into "UTF-8" format

String url=java.net.URLDecoder.decode(crawlUrl,"UTF-8");

Method Two:

Convert the front-end url to json format

string url=JSON.stringify("https://blog.csdn.net")

Of course, there are many related solutions on the Internet. If you encounter such problems, you can find a solution that suits you according to your business needs.

Guess you like

Origin blog.csdn.net/yyp0304Devin/article/details/113242763