【发布时间】:2011-09-16 22:14:42
【问题描述】:
我是 Jersey 和 REST 的新手,所以如果我的问题太愚蠢,请见谅。我有一个名为 Places 的简单资源,它应该支持 GET 操作,该操作根据输入变量返回一些兴趣点。这是输入字符串和类:
错误:
HTTP 415 - Unsupported Media Type
输入网址:
http://localhost:8080/RESTGO/rest/places?latitude=2&longitude=3&radius=3&types=food
类:
@Path("/places")
public class Places {
@GET
@Produces(MediaType.APPLICATION_JSON)
public JSONObject getPlaces(@QueryParam("latitude") double latitude,
@QueryParam("longitude") double longitude,
@QueryParam("radius") int radius,
@QueryParam("types") String types,
@DefaultValue("true") boolean sensor) {
GooglePlacesClient google = new GooglePlacesClient();
JSONObject json = null;
try {
String response = google.performPlacesSearch(latitude, longitude, radius, types, sensor);
json = new JSONObject(response);
} catch (Exception e) {
e.printStackTrace();
}
return json;
}
}
【问题讨论】:
-
您接受
application/json机构吗?将 http-header 设置为 application/json(标头名称:Accept,值 =application/json)