How is a POST with parameters accomplished using the Google HTTP Java client library?

100 views
Skip to first unread message

/dev /local/ca

unread,
Nov 11, 2020, 1:57:32 AM11/11/20
to google-api-java-client
How is a POST with parameters accomplished using the Google HTTP Java client library?

This does not work:

public void run() throws Exception {

HttpRequestFactory requestFactory
= new NetHttpTransport().createRequestFactory();

String myPostURL = "https://my-post-url"

//String params = "{'userid': 'me', 'password': 'mk8e!'}";
String params = "{\"userid\": \"me\", \"password\": \"mk8e!\"}";
HttpContent content = ByteArrayContent.fromString("application/json", params);
GenericUrl url = new GenericUrl(myPostURL);
HttpRequest request = requestFactory.buildPostRequest(url, content);

HttpResponse response = request.execute();
}
I get a message back from the server:
Bad request. Parameter userid not found. Parameter password not found
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1113)

google-http-java-client
Reply all
Reply to author
Forward
0 new messages