【问题标题】:$http.post URL is getting trimmed off if URL has "#"如果 URL 带有“#”,则 $http.post URL 将被剪掉
【发布时间】:2017-09-12 09:43:58
【问题描述】:

我有一个 Rest API:/myApp/fetchData/User-Name/Password。用户名和密码将根据请求更改。

当我像这样调用上面的restapi时

/myApp/fetchData/srikanth/Abcdef#g123

请求是这样的:

/myApp/fetchData/srikanth/Abcdef

基本上在 URL 文本中已从 # 字符中删除。有什么办法解决吗?

谢谢, 斯里坎特。

【问题讨论】:

    标签: angularjs rest http-post


    【解决方案1】:

    在 URI 中,# 触发 "fragment" 的开头,并结束路径。片段通常指定由路径标识的资源的一部分。

    当您发布来自客户端的请求时,您必须escape special characters。您的要求应该是:

    /myApp/fetchData/srikanth/Abcdef%23g123
    

    转义 url 有不同的方法,比如 JS 中的 encodeURI 或 encodeURIComponent 函数。例如,您可以这样做:

    var request = "/myApp/fetchData/srikanth/" + encodeURIComponent("Abcdef#g123");
    

    然后服务器必须解码回原始请求。

    但是:您确定以这种方式发送纯密码是一个好的解决方案吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-15
      相关资源
      最近更新 更多