简体   繁体   English

带空格的 URL rest api 参数

[英]URL rest api parameter with spaces

I am using the rest API of JIRA to retrieve issues while filtering on the project name and issue type.我正在使用 JIRA 的其余 API 来检索问题,同时过滤项目名称和问题类型。

When I try to use an API call like:当我尝试使用 API 调用时:

String url3 = "jiraURL/rest/api/2/search?jql=project=GB AND issuetype=Requirement&maxResults=1000";

It works!有用!

But when I try:但是当我尝试:

  String url3 = jiraURL/rest/api/2/search?jql=project=GB AND issuetype=Product Risk&maxResults=1000";

I got HttpClientErrorException: 400 .我得到了HttpClientErrorException: 400 Meaning my URL is wrong.这意味着我的网址是错误的。 I think the error lies in the fact that there is a space between the two words that are the issuetype.我认为错误在于问题类型这两个词之间有一个空格。

I already tried putting + instead of spaces but that doesn't work.我已经试过用 + 代替空格,但这不起作用。 My first call works perfectly.我的第一个电话工作得很好。 But I don't know how to solve the second call.但我不知道如何解决第二个电话。

Each parameter name and value should be URL encoded.每个参数名称和值都应进行 URL 编码。 They should then be joined with a separator (either '&' or ';').然后它们应该用一个分隔符('&' 或 ';')连接起来。 Looking at看着

...?jql=project=GB AND issuetype=Product Risk&maxResults=1000

I'm not sure whether jql , project and issuetype are separate parameters or if the whole string is a value for jql .我不确定jqlprojectissuetype是否是单独的参数,或者整个字符串是否是jql的值。 If the former, the spaces should be replaced with their URL-encoded form ("%20"):如果是前者,空格应替换为其 URL 编码形式(“%20”):

...?jql=&project=GB%20AND%20issuetype=Product%20Risk&maxResults=1000

If the latter, the "="s should also be URL-encoded:如果是后者,“=”也应该是 URL 编码的:

...?jql=project%3DGB%20AND%20issuetype%3DProduct%20Risk&maxResults=1000

Can you please try?你能试试吗?

 try {
        String url3 = URLEncoder.encode("jiraURL/rest/api/2/search?jql=project=GB AND issuetype=Product Risk&maxResults=1000", "UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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