如何使用 Google HTTP 客户端进行 POST、PUT 和 DELETE:
@Test
public void testGetDBs() throws IOException {
GooUrl url = new GooUrl(GOO_URL);
List<String> path = new LinkedList<String>();
path.add("users");
path.add("id1");
url.setPathParts(path);
url.fields = "";
HttpRequest request;
try {
request = requestFactory.buildGetRequest(url);
request.setMethod(HttpMethod.POST);
String result = request.execute().parseAsString();
System.out.println("Result = " + result);
} catch (Exception e) {
e.printStackTrace();
}
}
假设我需要发布一个 JSON 字符串,该怎么做?另外,设置内容长度和类型。