大佬教程收集整理的这篇文章主要介绍了无法使用 Volley 获得 HTTPS 响应,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我一直在尝试了解 Volley,因此我制作了一个简单的应用程序,它有一个连接按钮,当按下按钮时,它会将响应显示为 TOAST,但是当我按下按钮时,我无法同时发送 TOAST 消息(响应 TOAST 和错误 TOAST)
这是 kotlin 代码:
import androID.icu.lang.UCharacter.GraphemeClusterBreak.L
import androIDx.appcompat.app.AppCompatActivity
import androID.os.bundle
import androID.util.Log
import androID.Widget.button
import androID.Widget.Toast
import com.androID.volley.request
import com.androID.volley.requestQueue
import com.androID.volley.Response
import com.androID.volley.toolBox.Stringrequest
import com.androID.volley.toolBox.Volley
class MainActivity : AppCompatActivity() {
private val url = "https://run.mocky.io/v3/f2721dfa-df49-4c27-b1a3-4929b6b75de1"
private var RQ : requestQueue? = null
overrIDe fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceStatE)
setContentVIEw(R.layout.activity_main)
val button = findVIEwByID<button>(R.ID.con_buttom)
button.setonClickListener {sendrequest()}
}
fun sendrequest()
{
val Stringrequest = Stringrequest(
request.Method.GET,url,{response -> Onresponse(responsE)},{Toast.makeText(applicationContext,"Couldn't Connect",Toast.LENGTH_SHORT).show()})
RQ?.add(Stringrequest)
}
fun Onresponse(response : String)
{
Toast.makeText(getApplicationContext(),"Response :" + response.toString(),Toast.LENGTH_LONG).show()
}
}
这里是xml代码:
<?xml version="1.0" enCoding="utf-8"?>
<androIDx.consTraintlayout.Widget.ConsTraintLayout xmlns:androID="http://scheR_690_11845@as.androID.com/apk/res/androID"
xmlns:app="http://scheR_690_11845@as.androID.com/apk/res-auto"
xmlns:tools="http://scheR_690_11845@as.androID.com/tools"
androID:layout_wIDth="match_parent"
androID:layout_height="match_parent"
tools:context=".MainActivity">
<button
androID:ID="@+ID/con_buttom"
androID:layout_wIDth="wrap_content"
androID:layout_height="wrap_content"
androID:text="Connect"
app:layout_consTraintBottom_toBottomOf="parent"
app:layout_consTraintEnd_toEndOf="parent"
app:layout_consTraintStart_toStartOf="parent"
app:layout_consTrainttop_totopOf="parent" />
</androIDx.consTraintlayout.Widget.ConsTraintLayout>
这是网址链接:https://run.mocky.io/v3/f2721dfa-df49-4c27-b1a3-4929b6b75de1
请帮帮我。我只是一个初学者 提前致谢:)
添加
RQ = Volley.newrequestQueue(this)
之后
setContentView(R.layout.activity_main)
在您的 onCreate
方法中。
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceStatE)
setContentView(R.layout.activity_main)
RQ = Volley.newrequestQueue(this)
val button = findViewById<Button>(R.id.con_buttom)
button.setOnClickListener { sendrequest() }
}
它不起作用,因为您的 RQ 为空
以上是大佬教程为你收集整理的无法使用 Volley 获得 HTTPS 响应全部内容,希望文章能够帮你解决无法使用 Volley 获得 HTTPS 响应所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。