解码 WebTarget URI

问题描述 投票:0回答:1

我的房产文件中有一项房产

appointments.deleteAppointmentwithReasonApi=api/appointment/{id}?reason={reason}
URL=http://xyz/etc/

在另一个文件中

public static final String  DELETE_APPOINTMENT_REASON = PropertiesUtil.getPropertyValueFromKey(REST_WEBSERVICE_URLS_PROP_FILE,
            "appointments.deleteAppointmentwithReasonApi"); // To get API name
public static final String URL = ServicesUtil.getURL(); // to get endpoint URL

在我的java API调用中,我给出了这样的东西

WebTarget target = client.target(CommonConstants.URL)
                    .path(CommonConstants.DELETE_APPOINTMENT_REASON)
                    .resolveTemplate("id", appointmentID).resolveTemplate("reason", reason);
            System.out.println(target);

我的回复是这样打印的...

JerseyWebTarget { http://xyz/etc/api/appointment/abc-123-ced-456%3Freason=Test }

没有访问正确的 Web 服务...我希望它是这样的

JerseyWebTarget { http://xyz/etc/api/appointment/abc-123-ced-456?reason=Test }

我知道我需要对 URL 进行编码。我无法以某种方式做到这一点。有什么建议吗?

java jsp uri encode
1个回答
0
投票

由于“?”,我对 uri“https://host.com:9343/igi/v2/agc/users?groupId=1”也有同样的问题。性格。

尝试使用以下代码:

WebTarget webTarget = this.getClient().path(endpointURL).queryParam("groupId", groupId);

使用 queryParam 方法,它将以正确的格式构建 uri 参数。

© www.soinside.com 2019 - 2024. All rights reserved.