我目前正在使用GsonRequest发出其余的GET请求.不清楚PUT请求的用途,我需要通过整个JSon对象发送更新.Request对象将接受PUT,但我不确定如何放置预期的JSon对象.
这是我的json要PUT:
{
prop1 : true,
prop2 : false,
prop4 : true
}
Run Code Online (Sandbox Code Playgroud)
以下是它在apiary.io中的提交方式,例如:
var xhr = new XMLHttpRequest();
xhr.open('PUT', 'http://my.apiary.io/v1/records/{myid}.json');
xhr.send("{\n \"isEditable\": false,\n \"isClosed\": true,\n \"isAvail\": true\n}");
Run Code Online (Sandbox Code Playgroud)
我不知道把JSON放在哪里.
谢谢
public class GsonRequest<T> extends Request<T> {
private final Gson gson ;
private final Class<T> clazz;
private final Map<String, String> headers;
private final Listener<T> listener;
public GsonRequest(int method, String url, Class<T> clazz, Map<String, String> headers,
Listener<T> listener, ErrorListener errorListener) {
super(method, url, errorListener);
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(Timestamp.class, new TimestampDeserializer()); …Run Code Online (Sandbox Code Playgroud) 我正在使用Android Volley库发送POST请求.并POST请求
Content-Type:application/jsonJson String但无论如何,我要改变它Volley Request Header,它总是被设定为Content-Type:text/html.这给了我400 Bad Request.这是我的课程POST请求Volley
public class GsonRequest<T> extends Request<T> {
private final Class<T> clazz;
private final Map<String, String> headers;
private final Listener<T> listener;
private Map<String, String> postParams;
private String postString = null;
/**
* Make a GET request and return a parsed object from JSON.
*
* @param url
* URL of the request to make
* …Run Code Online (Sandbox Code Playgroud)