发送 POST 请求到 Google 表单 returns 代码 400

Sending a POST request to Google Forms returns code 400

在我的 android 应用程序中,我尝试向 Google 表单发送 POST 请求,但返回错误 400:

400 https://docs.google.com/forms/d/e/[form-id-number-here]/formResponse (114002ms)
content-type: text/html; charset=utf-8
x-robots-tag: noindex, nofollow, nosnippet
cache-control: no-cache, no-store, max-age=0, must-revalidate
pragma: no-cache
expires: Mon, 01 Jan 1990 00:00:00 GMT
date: Sun, 17 Mar 2019 05:03:05 GMT
p3p: CP="This is not a P3P policy! See g.co/p3phelp for more info."
p3p: CP="This is not a P3P policy! See g.co/p3phelp for more info."
x-chromium-appcache-fallback-override: disallow-fallback
x-content-type-options: nosniff
x-xss-protection: 1; mode=block
server: GSE
....

这是我的代码:

interface FormApi {
    @Headers("Content-Type: application/json",  "Accept: text/html", "Cache-Control: no-cache")
    @POST("{key}/formResponse")
    fun formResponseJson(@Path("key") key: String, @Body json: JsonObject): Call<ResponseBody>

}

用法:

val gson = GsonBuilder().setLenient().create()
val client = OkHttpClient.Builder()
            .readTimeout(timeout.toLong(), TimeUnit.SECONDS)
            .connectTimeout(timeout.toLong(), TimeUnit.SECONDS)
            .build()
val retrofit = Retrofit.Builder()
            .baseUrl(url)
            .addConverterFactory(GsonConverterFactory.create(gson))
            .client(client)
            .build()
val api = retrofit.create(FormApi::class.java)
val json = dataObj.toJson()
val call = api.formResponseJson(key, json)
call.enqueue(CallBackResult(resultReceiver))   

请注意,json 对象的键值格式如下:{"entry.xxxxx1":"Test"}

有谁知道为什么会返回此错误代码?有没有人在 Android 中成功将 POST 发送到 Google 表单?

谢谢。

我做了如下修改,代码现在可以post到Google形式:

在 FormApi 中:

    POST("{key}/formResponse")
    @FormUrlEncoded
    fun formResponse(@Path("key") key: String,  @FieldMap hashmap: HashMap<String, Any>): Call<ResponseBody>

用法:

val call = api.formResponse(key, hash)

其中 "hash" 是一个具有字段实际值的 HashMap(不是 URLEncoded)