Java的Google表单填充

问题描述 投票:0回答:1

我需要从我的Java代码中填写基本的Google表单,但是会抛出org.apache.http.client.ClientProtocolException: Unexpected response status: 405

这是我的代码:

private boolean sendMessage(UserInfo userInfo) {
    final HttpPost req = new HttpPost("my-form-url");
    try (CloseableHttpClient httpclient = HttpClients.createDefault()) {

        List<NameValuePair> form = new ArrayList<>();
        form.add(new BasicNameValuePair("entry.1301726507", userInfo.getName()));
        form.add(new BasicNameValuePair("entry.1466759457", "hello"));
        UrlEncodedFormEntity entity = new UrlEncodedFormEntity(form, Consts.UTF_8);

        req.setEntity(entity);
        System.out.println("Executing request " + req.getRequestLine());

        ResponseHandler<String> responseHandler = response -> {
            int status = response.getStatusLine().getStatusCode();
            if (status >= 200 && status < 300) {
                HttpEntity responseEntity = response.getEntity();
                return responseEntity != null ? EntityUtils.toString(responseEntity) : null;
            } else {
                throw new ClientProtocolException("Unexpected response status: " + status);
            }
        };
        String responseBody = httpclient.execute(req, responseHandler);
        System.out.println("----------------------------------------");
        System.out.println(responseBody);
        return true;
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }

这里是表格:

enter image description here

我在做什么错?

java google-form autofill
1个回答
0
投票
您可以使用我的宠物项目为您完成工作:
© www.soinside.com 2019 - 2024. All rights reserved.