这段代码曾经可以工作,但现在它会抛出一个错误,例如:“failure android.os.networkonmainthreadexception com.github.kittinunf.fuel.core.FuelError $Companion.wrap(FuelError.kt:85)” ... 等等. 它可以与什么连接?在清单中,我还注册了对 Internet 的访问权限。用英语讲。网站似乎有解决方案,但我是英文的。不是真的,但你自己通过翻译知道一些事情......
package com.example.indx
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.github.kittinunf.fuel.Fuel
import com.github.kittinunf.fuel.core.Headers
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val bodyJson = """{"ApiContext":{"Login":"xxx","Wmid":"123456789","Culture":"ru-RU","Signature":"gdfgkgjdfkgjdfkgdfjkgdfjk="}}"""
val (requested, responsed, resulted) = Fuel.post("https://api.indx.ru/api/v2/trade/Tools")
.body(bodyJson)
.header(Headers.CONTENT_TYPE, "text/json")
.header(Headers.USER_AGENT, "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36")
.responseString()
yaz.append(resulted.toString())
}
}