请您评论此客户端重定向代码有什么问题。
有必要:
X-MF-Auth-Token
发布请求会产生“400”错误。非常感谢你!
ClientResource cr = new ClientResource(servername + "/json/place");
cr.getRequest().getAttributes().put("X-MF-Auth-Token", token);
Form form = new Form ();
form.add("Category", "");
form.add("CategoryId", "A1EECAB9-3E66-4F14-92E9-465EDFB22BA7");
form.add("Latitude", "0");
form.add("Longitude", "0");
form.add("Name", "Loremipsum");
form.add("PlaceId", "00000000-0000-0000-0000-000000000099");
cr.post(form, MediaType.APPLICATION_JSON);
if (cr.getStatus().isSuccess()) {
// Register Successful
Log.v("Register()", "Successeful");
return true;
} else {
Log.v("Register()", "ERROR");
return false;
}
} catch (ResourceException e) {
// Login Error
Log.v("AddPlace() error:", e.getStatus().toString());
return false;
}
答案 0 :(得分:1)
您可以使用JSONObject而不是Form:
JSONObject jo = new JSONObject();
try {
jo.add("Category", "");
jo.add("CategoryId", "A1EECAB9-3E66-4F14-92E9-465EDFB22BA7");
jo.add("Latitude", "0");
jo.add("Longitude", "0");
jo.add("Name", "Loremipsum");
jo.add("PlaceId", "00000000-0000-0000-0000-000000000099");
} catch (JSONException ex) {
}
cr.post(new JsonRepresentation(jo), MediaType.APPLICATION_JSON);
答案 1 :(得分:0)
我认为您不将X-MF-Auth-Token
添加到标题中。
试
Form headers = (Form) cr.getRequest().getAttributes("org.restlet.http.headers");
if (headers == null) {
headers = new Form();
cr.getRequest().getAttributes.put("org.restlet.http.headers", headers);
}
headers.add("X-MF-Auth-Token", token);