简体   繁体   中英

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.

When I try to use an API call like:

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 . 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. 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 . If the former, the spaces should be replaced with their URL-encoded form ("%20"):

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

If the latter, the "="s should also be URL-encoded:

...?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();
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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