【问题标题】:How to pass an url by a rest api URL string如何通过rest api URL字符串传递url
【发布时间】:2020-10-19 12:17:03
【问题描述】:

我有一个表,其中包含 pageId 和 page_name 等列,其中值插入行 [1,https://google.com] 等。

现在我创建了一个获取 URL 并返回 pageid 的 api,所以现在的场景是这样的:

localhost:8080/api/v1/page/https://google.com

每当我试图通过 Postman 传递它时,都会显示 无法发送响应 谁能帮我解决这个问题?

【问题讨论】:

  • url 语法似乎不正确。
  • 在这种情况下,最好使用参数而不是路径值。但无论如何,尝试对 URL 进行 URI 编码。
  • 嗨@RealSkeptic,它有效,因为我使用参数而不是路径变量。非常感谢您的快速回复。请回答问题,以便我可以接受,这可以帮助其他人。

标签: java spring spring-boot rest spring-data-jpa


【解决方案1】:

问题是您在查询参数中保留了字符。

考虑encoding你的文字。

所以: http://www.google.com

将变为: http%3A%2F%2Fwww.google.com

【讨论】:

    【解决方案2】:
    localhost:8080/api/v1/page/https://google.com
    

    根据 url 格式文档(参见例如 this article)- 不可能使用保留字符(: 和 /)作为参数。我建议使用类似的东西

    localhost:8080/api/v1/page/google.com
    

    并在服务中添加“https://”

    或使用

    localhost:8080/api/v1/page/https~~google.com 
    

    并将“~~”替换为“://”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-05
      • 1970-01-01
      • 1970-01-01
      • 2019-06-03
      • 1970-01-01
      • 1970-01-01
      • 2015-02-03
      • 1970-01-01
      相关资源
      最近更新 更多