【问题标题】:How to shorten a url that contained "#" symbol by TinyURL api?如何通过 TinyURL api 缩短包含“#”符号的 url?
【发布时间】:2020-05-10 18:15:56
【问题描述】:

比如我想缩短这个网址:https://docs.python.org/3/library/subprocess.html#popen-constructor

我尝试将https://docs.python.org/3/library/subprocess.html#popen-constructor作为url参数传递,但返回的url实际上是从https://docs.python.org/3/library/subprocess.html缩短的,所以它不会跳转到popen-constructor部分。

然后我尝试将https://docs.python.org/3/library/subprocess.html%23popen-constructor作为url参数传递,但是返回的url不起作用(404未找到)。

唯一的解决方案是自己使用 TinyURL 的网站,所以我想知道是否可以通过 TinyURL api 缩短包含“#”符号的 url?

【问题讨论】:

    标签: php api webapi short-url tinyurl


    【解决方案1】:

    注意:由于 stackoverflow 安全规则,我无法添加小 URL。因此,在下面的每个示例中,我都将 https://tinyurl.com 替换为 https://<tinyurl>.com

    您应该对整个目标网址进行编码,即:

    https%3A%2F%2Fdocs.python.org%2F3%2Flibrary%2Fsubprocess.html%23popen-constructor
    

    然后,如果您将 api 与完全编码的目标 url 一起使用,它将创建一个正确的短链接:

    https://<tinyurl>.com/api-create.php?url=https%3A%2F%2Fdocs.python.org%2F3%2Flibrary%2Fsubprocess.html%23popen-constructor
    

    创建的 Tinyurl (https://&lt;tinyurl&gt;.com/q3anmqb) 将重定向到 https://docs.python.org/3/library/subprocess.html#popen-constructor

    【讨论】:

    • 嗨@PenutChen,如果它解决了问题,请将问题标记为已回答。谢谢。
    猜你喜欢
    • 2012-01-09
    • 2011-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-23
    • 1970-01-01
    相关资源
    最近更新 更多