httr 有时会在 URL 中将“%”替换为“%25”
httr replaces "%" with "%25" in URL sometimes
当使用 httr::GET
时,在某些查询中它将 %
替换为安全表示 %25
,但在其他查询中它不会。我找不到任何可以实现这种情况的规则。
我正在使用 httr 1.4.1
替换 %
的示例查询(请注意错误代码,并且输入的 URL 与返回的响应对象不同):
> httr::GET("jira.spring.io/rest/api/latest/search?jql=project=Spring%20Framework&startAt=0")
Response [https://jira.spring.io/rest/api/latest/search?jql=project=Spring%2520Framework&startAt=0]
Date: 2020-01-16 22:57
Status: 400
Content-Type: application/json;charset=UTF-8
Size: 196 B
查询没有替换的地方(没有错误,URL响应与输入相同):
> httr::GET("issues.jenkins-ci.org/rest/api/latest/search?jql=project='WEBSITE'%20OR%20project='Infrastructure'&startAt=0")
Response [https://issues.jenkins-ci.org/rest/api/latest/search?jql=project='WEBSITE'%20OR%20project='Infrastructure'&startAt=0]
Date: 2020-01-16 23:02
Status: 200
Content-Type: application/json;charset=UTF-8
Size: 430 kB
这是怎么回事?这是httr中的错误吗?或者我应该在 GET()
调用中更改一些参数?
tldr; 将 HTTPS 请求与 jira.spring.io 一起使用以避免协议升级中断。
这不是 R/HTTR 问题。这是网站。比较 HTTP ("failing with mystery %25") 和 HTTPS ("succeeding") 的结果:
http://jira.spring.io/rest/api/latest/search?jql=project=Spring%20Framework&startAt=0
{"errorMessages":["Error in the JQL Query: The character '%' is a reserved JQL character. You must enclose it in a string or use the escape '\u0025' instead. (line 1, character 15)"],"errors":{}}
https://jira.spring.io/rest/api/latest/search?jql=project=Spring%20Framework&startAt=0
{"errorMessages":["Error in the JQL Query: Expecting either 'OR' or 'AND' but got 'Framework'. (line 1, character 16)"],"errors":{}}
在 HTTP -> HTTPS 重定向协议升级中似乎有一个 'malfunction',它有这个响应头:
Status Code: 301 Moved Permanently
Location: https://jira.spring.io/rest/api/latest/search?jql=project=Spring%252520Framework&startAt=0
^^^^^
因此一个解决方案是使用 HTTPS 端点 并避免奇怪的目标位置..
当使用 httr::GET
时,在某些查询中它将 %
替换为安全表示 %25
,但在其他查询中它不会。我找不到任何可以实现这种情况的规则。
我正在使用 httr 1.4.1
替换 %
的示例查询(请注意错误代码,并且输入的 URL 与返回的响应对象不同):
> httr::GET("jira.spring.io/rest/api/latest/search?jql=project=Spring%20Framework&startAt=0")
Response [https://jira.spring.io/rest/api/latest/search?jql=project=Spring%2520Framework&startAt=0]
Date: 2020-01-16 22:57
Status: 400
Content-Type: application/json;charset=UTF-8
Size: 196 B
查询没有替换的地方(没有错误,URL响应与输入相同):
> httr::GET("issues.jenkins-ci.org/rest/api/latest/search?jql=project='WEBSITE'%20OR%20project='Infrastructure'&startAt=0")
Response [https://issues.jenkins-ci.org/rest/api/latest/search?jql=project='WEBSITE'%20OR%20project='Infrastructure'&startAt=0]
Date: 2020-01-16 23:02
Status: 200
Content-Type: application/json;charset=UTF-8
Size: 430 kB
这是怎么回事?这是httr中的错误吗?或者我应该在 GET()
调用中更改一些参数?
tldr; 将 HTTPS 请求与 jira.spring.io 一起使用以避免协议升级中断。
这不是 R/HTTR 问题。这是网站。比较 HTTP ("failing with mystery %25") 和 HTTPS ("succeeding") 的结果:
http://jira.spring.io/rest/api/latest/search?jql=project=Spring%20Framework&startAt=0
{"errorMessages":["Error in the JQL Query: The character '%' is a reserved JQL character. You must enclose it in a string or use the escape '\u0025' instead. (line 1, character 15)"],"errors":{}}
https://jira.spring.io/rest/api/latest/search?jql=project=Spring%20Framework&startAt=0
{"errorMessages":["Error in the JQL Query: Expecting either 'OR' or 'AND' but got 'Framework'. (line 1, character 16)"],"errors":{}}
在 HTTP -> HTTPS 重定向协议升级中似乎有一个 'malfunction',它有这个响应头:
Status Code: 301 Moved Permanently
Location: https://jira.spring.io/rest/api/latest/search?jql=project=Spring%252520Framework&startAt=0
^^^^^
因此一个解决方案是使用 HTTPS 端点 并避免奇怪的目标位置..