我使用curl发送HTTP POST
请求:
curl -i -X POST -H "Content-Type:application/json" -d '{"geometry":{"type":"Point","coordinates":[42.3581,-71.0636]}}' http://localhost:8180/GoogleMapsLoadingTest/GoogleMapsErp/EQUI/
我称之为jersey
方法:
@POST
@Path("/{objtype}")
@Consumes(MediaType.APPLICATION_JSON)
public Response createUsingPost(@PathParam("objtype") String objtype,String objstr)
{
JSONParser parser=new JSONParser();
JSONObject obj=null;
try {
obj=(JSONObject) parser.parse(objstr);
} catch (ParseException e) {
e.printStackTrace();
}
JSONObject geo=(JSONObject) obj.get("geometry");
...
...
}
我在terminal
中收到此错误:
HTTP/1.1 415 Unsupported Media Type
Server: Apache-Coyote/1.1
Content-Length: 0
Date: Mon, 05 May 2014 05:52:02 GMT
我在Eclipse控制台中收到此错误:
SEVERE: A message body reader for Java class org.json.simple.JSONObject, and Java type
class org.json.simple.JSONObject, and MIME media type application/json was not found.
The registered message body readers compatible with the MIME media type are:
application/json ->
com.sun.jersey.json.impl.provider.entity.JSONJAXBElementProvider$App
com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider$App
com.sun.jersey.json.impl.provider.entity.JSONListElementProvider$App
*/* ->
com.sun.jersey.core.impl.provider.entity.FormProvider
com.sun.jersey.core.impl.provider.entity.StringProvider
com.sun.jersey.core.impl.provider.entity.ByteArrayProvider
com.sun.jersey.core.impl.provider.entity.FileProvider
com.sun.jersey.core.impl.provider.entity.InputStreamProvider
com.sun.jersey.core.impl.provider.entity.DataSourceProvider
com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$General
com.sun.jersey.core.impl.provider.entity.ReaderProvider
com.sun.jersey.core.impl.provider.entity.DocumentProvider
com.sun.jersey.core.impl.provider.entity.SourceProvider$StreamSourceReader
com.sun.jersey.core.impl.provider.entity.SourceProvider$SAXSourceReader
com.sun.jersey.core.impl.provider.entity.SourceProvider$DOMSourceReader
com.sun.jersey.json.impl.provider.entity.JSONJAXBElementProvider$General
com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$General
com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$General
com.sun.jersey.core.impl.provider.entity.XMLRootObjectProvider$General
com.sun.jersey.core.impl.provider.entity.EntityHolderReader
com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider$General
com.sun.jersey.json.impl.provider.entity.JSONListElementProvider$General