android kotlin凌空慢请求副本获取请求
我使用排球框架向我的烧瓶API提出请求。这是我用来做到这一点的语法:
val jsonObjectRequest =
JsonObjectRequest(Request.Method.GET, url, null, { response ->
val spiScanApiResponse = response["success"] as String
if (spiScanApiResponse == "true") {
Toast.makeText(this, "SCANS SENT WITH SUCCESS!", Toast.LENGTH_LONG).show()
finish()
} else {
Toast.makeText(
this,
"SCANS WERE NOT SENT!",
Toast.LENGTH_LONG
)
.show()
}
},
{
}
)
queue.add(jsonObjectRequest)
我得到了这个“凌空:[111] networkutility.logslowrequests:request request =< [] http:// myurl 0xbeaaf2f6 http响应= 114],[rc = 200],[retrycount = 1]”,这正在重复get请求,并将数据发送两倍到我的数据库。
从我阅读的内容来看,这是一个重试 /超时的问题,但是我找不到任何可以帮助使用Kotlin的东西,我得到的所有可能的答案都在Java中,我在Google上找不到有关Retrypolicy或超时的Kotlin版本的任何内容。
有没有一种方法可以使用凌空进行这项工作?我不想将所有请求切换到另一个框架,因为这是唯一不起作用的请求。
谢谢你!
I use the Volley framework to make GET requests to my Flask API. This is the syntax I use to do that:
val jsonObjectRequest =
JsonObjectRequest(Request.Method.GET, url, null, { response ->
val spiScanApiResponse = response["success"] as String
if (spiScanApiResponse == "true") {
Toast.makeText(this, "SCANS SENT WITH SUCCESS!", Toast.LENGTH_LONG).show()
finish()
} else {
Toast.makeText(
this,
"SCANS WERE NOT SENT!",
Toast.LENGTH_LONG
)
.show()
}
},
{
}
)
queue.add(jsonObjectRequest)
I am getting this "Volley: [111] NetworkUtility.logSlowRequests: HTTP response for request=<[ ] https://myUrl 0xbeaaf2f6 NORMAL 1> [lifetime=6596], [size=114], [rc=200], [retryCount=1]" and this is duplicating the GET request and sends twice the data to my database.
From what I read it's a RetryPolicy / Timeout issue, but I can't find anything to help using Kotlin, all the possible answers I get are in Java and I can't find anything on Google about Kotlin Version of RetryPolicy or Timeout.
Is there a way to make this work using Volley? I wouldn't want to switch all my requests to another framework as this is the only request that does not work.
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我终于弄清楚了,这是在Kotlin中:
不再需要重复的请求,我必须设置
JSONOBJECTREQUEST.RETRYPOLICY.RETRYPOLICY
在将其添加到这样的队列之前:就是这样。
现在它就像魅力一样!
我希望这也会对他人有所帮助。
I finally figured it out and here it is how, in Kotlin:
to no more have duplicated requests I had to set the
jsonObjectRequest.retryPolicy
before adding it to the queue like this:And that's it.
Now it works like a charm!
I hope this will help others too.