简体   繁体   中英

URL Protocol: How to send a parameter with space to run a windows program?

In the Browser, if I send a URL with a parameter that includes a space to a program, the program will get a parameter %20 and this results in an error.

The parameter is a random parameter, and I can't modify the program to read the parameter, because this program is not developed by me.

There is nothing you can do about this if you can't modify it. The program apparently does not handle URL encoding, and you will need to modify it to tell it to handle URL encoding, as the %20 is a space in URLs.

Create a file with the following content and save it as index.html :

<html>
  <body>
    <script>
      let query = window.location.search;
      let decoded = decodeURI(query);
      document.write(decoded);
    </script>
  </body>
</html>

Now open the file in the browser and add a query parameter to it, like this:

index.html?param=some words

The page will show

?param=some words

You need to tell the programmer that created the page that this is the way to decode correctly.

Actually you need to split the query by ampersand (&) first, and then split each part by equals (=), and then decode each parameter value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM