如何使用Google HttpClient API进行HTTP POST?
如何使用Google HTTP Client Library for Java完成带有参数的帖子 这不起作用:如何使用Google HttpClient API进行HTTP POST?,post,google-api,http-post,google-http-client,Post,Google Api,Http Post,Google Http Client,如何使用Google HTTP Client Library for Java完成带有参数的帖子 这不起作用: public void post() throws Exception { HttpRequestFactory requestFactory = new NetHttpTransport().createRequestFactory(); String myPostURL = "https://my-post-url
public void post() throws Exception {
HttpRequestFactory requestFactory
= new NetHttpTransport().createRequestFactory();
String myPostURL = "https://my-post-url"
//String params = "{'userid': 'me', 'password': 'jt48e!'}";
String params = "{\"userid\": \"me\", \"password\": \"jt48e!\"}";
HttpContent content = ByteArrayContent.fromString("application/json", params);
GenericUrl url = new GenericUrl(myPostURL);
HttpRequest request = requestFactory.buildPostRequest(url, content);
HttpResponse response = request.execute();
}
我在呼叫时收到一条错误消息:
Bad request. Parameter userid not found. Parameter password not found.
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1113)
Google HttpClient库java 谷歌http java客户端 谷歌http客户端