如何在StringRequest中发送参数?

时间:2019-11-21 11:55:41

标签: android kotlin android-volley

class test2 : AppCompatActivity(){

 override fun onCreate(savedInstanceState: Bundle?)
 {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_test2)
    connect()

 }

 fun connect(){
    val queue = Volley.newRequestQueue(this)
    val url = "https://www.example.com/Register.php"
    val params = HashMap<String,String>()
    params["abc"] = "parm1"
    params["def"] = "parm2"
    params["ghi"] = "parm3"

    val stringRequest = StringRequest(Request.Method.POST, url,
        Response.Listener<String> { response ->
            text_test.text = "Response is: $response"
        },
        Response.ErrorListener { text_test.text = "That didn't work! " })
    queue.add(stringRequest)
  }
}

我想在StringRequest中而不是在JsonObjectRequest中发送参数。

参数应为"param1=data1&param2=data2&param3=data3"格式

和UTF-8编码。

有什么主意我该如何发送这种格式的数据?

0 个答案:

没有答案