gpt4 book ai didi

java - OKHTTP3 POST FORM android 应用程序不会向 Google Forms 发布任何内容

转载 作者:搜寻专家 更新时间:2023-11-01 09:45:16 27 4
gpt4 key购买 nike

我已阅读并理解此网页中的以下代码,作为开发我的 android 应用程序的引用: https://github.com/square/okhttp/blob/master/samples/guide/src/main/java/okhttp3/recipes/PostForm.java

public class PostForm extends AsyncTask<String, Void, String>
{
public static final MediaType FORM_DATA_TYPE = MediaType.parse("application/text; charset=utf-8");

String URL = "https://docs.google.com/forms/d/e/FILLERFORMTESTINGNOTREAL";
String USER_NAME = "entry.XXXXXXXXX"; //FAKE ENTRY
String PASSWORD = "entry.XXXXXXXXX"; //FAKE ENTRY

@Override
public String doInBackground(String... params)
{
String username = params[0];
String password = params[1];

try
{
OkHttpClient client = new OkHttpClient();

String post_data = USER_NAME + "=" + URLEncoder.encode(username, "UTF-8") +
"&" + PASSWORD + "=" + URLEncoder.encode(password, "UTF-8");

RequestBody requestBody = RequestBody.create(FORM_DATA_TYPE, post_data);

Request request = new Request.Builder()
.url(URL)
.post(requestBody)
.build();

client.newCall(request).execute();

}
catch (IOException e)
{
e.printStackTrace();
}

return null;

}

我做错了什么?android应用程序似乎成功提交了数据,但是当我查看Google Form时,没有输入任何数据?...请帮忙!

最佳答案

当我应该使用 FormBody 时却使用了 RequestBody...

            FormBody formBody = new FormBody.Builder()
.add(USERNAME, usr)
.add(PASSWORD, pwd)
.build();

糟糕!现在程序可以运行了,哈哈

关于java - OKHTTP3 POST FORM android 应用程序不会向 Google Forms 发布任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38342065/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com