错误Java Jersey:NotAuthorizedException:HTTP 401未经授权

时间:2016-02-10 20:00:44

标签: java xml rest jersey

我正在尝试调用XML文件API,但是我收到了这个错误。

我只需使用URL即可轻松打开浏览器上的.xml文件。

有人可以帮助我吗?

private ArrayList<Weather> weatherList = new ArrayList<>();

public String load(String city) {
    ClientConfig config = new ClientConfig();
    Client client = ClientBuilder.newClient(config);
    WebTarget target = client.target(getBaseURI());
    return target.path("data/2.5/weather?q="+city+"&mode=xml&appid=[API_KEY]").request().accept(MediaType.TEXT_XML).get(String.class);
}

public URI getBaseURI() {
    return UriBuilder.fromUri("http://api.openweathermap.org").build();
}
PS:嗯,我没有用过这个:

HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic(username, password);

client.register(feature);

因为通话不需要任何权限(没有用户名和密码)。

感谢。

0 个答案:

没有答案