如何使用Google HttpClient API进行HTTP POST?

问题描述

如何使用Java的Google HTTP客户端库完成带有参数的POST?

这不起作用:

 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

google-http-java-client

google-http-client

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)