【发布时间】:2015-05-04 18:34:17
【问题描述】:
我 POST 到如下端点:
import java.util.logging.Level;
import org.json.JSONException;
import org.json.JSONObject;
import org.restlet.ext.json.JsonRepresentation;
import org.restlet.representation.Representation;
import org.restlet.resource.Post;
import org.restlet.resource.ServerResource;
try {
JSONObject jsonToCallback = AcceptorManager.getJsonFromClient();
String test = jsonToCallback.getString("test");
String st2 = jsonToCallback.getString("st2");
ClientResource clientResource = new ClientResource(callback);
clientResource.setMethod(Method.POST);
Form form = new Form ();
form.add("key1", val1);
form.add("key2", "stat");
Representation representation = clientResource.post(form, MediaType.APPLICATION_JSON);
} catch (Exception e) {
//Here I get "Unsupported Media Type (415) - Unsupported Media Type"
}
这是终点:
public class test extends ServerResource{
@Post
public JSONObject testPost(JSONObject autoStackRep) throws JSONException, AcceptorException {
JSONObject json=new JSONObject();
try {
json.put("result",false);
json.put("id",1);
} catch (JSONException e) {
e.printStackTrace();
}
return json;
}
}
我该如何解决这个问题?
【问题讨论】:
-
请指定哪个库包含
@Post(不是@POST)注释。是 AndroidAnnotations(迄今为止我发现的最接近的)吗? -
谢谢@fori1ton。我已经编辑了我的问题。它的形式 restlet。
标签: java http restlet media-type