Tag: android volley

Android(Kotlin) – CookieHandler不能使用POST方法,但使用GET工作

我的应用程序中有两个POST方法。 一个是我把CookieHandler(代码: CookieHandler.setDefault(CookieManager()) )的CookieHandler.setDefault(CookieManager()) 。 在这个活动后,我得到了一些GET方法和cookies工作,但是当我想要使用另一个POST方法,我得到AuthFailurEerror 。 这是我的代码: LoginActivity: // this line is in onCreate method CookieHandler.setDefault(CookieManager()) private fun login2() { val req = object : StringRequest(Request.Method.POST, LOGIN_API_URL, Response.Listener { response -> Toast.makeText(this, response, Toast.LENGTH_LONG).show() val user = Intent(this, UserActivity::class.java) startActivity(user) }, Response.ErrorListener { e -> Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show() }) { public override fun getParams(): […]

Android Kotlin – Volley意外的响应代码500

我使用Django Rest Framework创建了REST API。 目前,我正在为我的网站开发移动应用程序。 当我做POST请求(这是我的应用程序中的第二个POST请求),我得到这个错误: E / Volley:[385] BasicNetwork.performRequest: http ://laude.ct8.pl/api/user/data/aktualizacja/意外的响应代码500 这是我的代码: private val UPDATE_URL = “http://laude.ct8.pl/api/user/data/aktualizacja/” private var volleyRequest: RequestQueue? = null private val jsonObj = JSONObject() volleyRequest = Volley.newRequestQueue(this) private fun aktualizacja() { jsonObj.put(“librus_user”, usernameEdit.text) jsonObj.put(“librus_pswd”, passwordEdit.text) val req = JsonObjectRequest(Request.Method.POST, UPDATE_URL, jsonObj, Response.Listener { response -> Toast.makeText(this, response.toString(), Toast.LENGTH_LONG).show() val user […]

Android Kotlin – Volley意外的响应代码400

我使用Django制作了REST API,现在我想将它连接到android。 我正在使用Kotlin和Volley库。 我创建的代码,我仍然得到这个错误: E / Volley:BasicNetwork.performRequest:用于http://laude.ct8.pl/api/user/login/的意外响应代码400。 这是我的Kotlin代码: val jsonObj = JSONObject() val LOGIN_API_URL = “http://laude.ct8.pl/api/user/login/” loginBtn.setOnClickListener { jsonObj.put(“username”, username.text) jsonObj.put(“password”, passwd.text) val que = Volley.newRequestQueue(this@MainActivity) val req = JsonObjectRequest(Request.Method.POST, LOGIN_API_URL, Response.Listener { response -> Toast.makeText(this@MainActivity, response.toString(), Toast.LENGTH_LONG).show() }, Response.ErrorListener { error -> Toast.makeText(this@MainActivity, error.toString(), Toast.LENGTH_LONG).show() }) que.add(req) } 我用Content-Type看到了这个问题,所以我尝试了这一行,并将其添加到jsonObj.put(“password”, passwd.text) 。 这里是这一行: jsonObj.put(“Content-Type”, “application/json”) […]

Volley-Mysql,Kotlintypes不匹配错误

我正在尝试通过API调用连接Mysql的Android应用程序。 我正在关注这篇文章来创建应用程序。 Volley with Kotlin using PHP and MySQL in Android Studio 3.0 但是我已经将mysql JSON结果填充到2个textView android对象中。 编译字符串请求时出现错误。 types不匹配:期望的字符串,find:int,以及在这里附加的另一个错误。 StringRequest函数错误 types不匹配错误 我的代码在这里。 我对这个Kotlin是新手,我无法弄清楚我的水平。 问题在哪里引起的。如何解决这个问题? //MainActivity.kt val requestQueue = Volley.newRequestQueue(this@MainActivity) downtxtvalue = findViewById(R.id.downtxt) as TextView uploadtxtvalue = findViewById(R.id.uptxt) as TextView //findViewById(R.id.btnGetspeed).setOnContextClickListener(getSpeed()){ val stringRequest = StringRequest(Request.Method.GET,URL_GET_ARTIST; Response.Listener { s -> try { val obj = JSONObject(s) if (!obj.getBoolean(“error”)) […]

不能用Volley发送多部分/表格数据

我有身体请求发送参数的问题。 对邮差我有成功的请求,但使用排雷我只得到意外的响应代码415错误代码。

我在Signal android项目中使用volleyplus和volley库

android { compileSdkVersion 23 buildToolsVersion '26.0.2' defaultConfig { applicationId "testing.gps_service" minSdkVersion 11 targetSdkVersion 22 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:23.4.0' compile 'com.android.volley:volley:1.0.0' compile 'dev.dworks.libs:volleyplus:+' compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7' testCompile 'junit:junit:4.12' compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" } repositories { mavenCentral() google() […]

用Android写入数据库

我试图用Kotlin在图书馆里使用Volley写数据库,当我尝试什么都没有发生时。 我用邮递员来查看服务器是否有问题,一切正常。 根据我的问题来自我的代码的这一部分: val stringRequest = object : StringRequest(Request.Method.POST, "myURL", Response.Listener<String> { response -> try { val obj = JSONObject(response) Toast.makeText(applicationContext, obj.getString("message"), Toast.LENGTH_LONG).show() } catch (e: JSONException) { e.printStackTrace() } }, object : Response.ErrorListener { override fun onErrorResponse(volleyError: VolleyError) { Toast.makeText(applicationContext, volleyError.message, Toast.LENGTH_LONG).show() } }) { @Throws(AuthFailureError::class) override fun getParams(): Map<String, String> { val params […]

在Kotlin中使用Android Volley进行String请求时获取java.lang.VerifyError

这一天我试图使用谷歌排球库(com.android.volley:volley:1.0.0)和下面的代码扔在Android 4.2.2上的java.lang.VerifyError,但在Android 6上工作正常,唯一不会在Android 4.2.2上崩溃的是当我在Response.Listener和Response.ErrorListener中注释掉了代码(在下面的代码中) inner class MyStringRequest(val agentNumber : String, val password : String) : StringRequest(Request.Method.POST,URL, Response.Listener<String> { if (it == "login_success") { getSharedPreferences("pref",0).edit().putBoolean("isSignedIn", true).commit() startActivity(Intent(applicationContext, MainActivity::class.java)); showProgress(false) finish() } else { mPasswordView!!.error = getString(R.string.error_incorrect_password) mPasswordView!!.requestFocus() showProgress(false) } }, Response.ErrorListener { it.printStackTrace() Toast.makeText(applicationContext, "Network error, Login Failed", Toast.LENGTH_LONG).show() showProgress(false) }) { override fun getParams(): MutableMap<String, […]

为什么我无法获取我的JSON文件的值?

您好,我正尝试在Android Studio中使用Kotlin提取我的JSON文件的数据: 这是我的JSON文件: val future = RequestFuture.newFuture < JSONObject > () val request = JsonObjectRequest("localhost", JSONObject(), future, future) val requestQueue = Volley.newRequestQueue(this) requestQueue.add(request) try { val array = JSONObject().getJSONArray("server_response") for (i in 0..array.length() – 1) { val objectYear = array.getJSONObject(i) val year = objectYear.getString("birthday") val response = future.get() // this will block textView2.setText(year.toString) // It […]

在Kotlin使用齐射的内存不足

我在Kotlin使用简单的StringRequest和Volley进行OutOfMemoryError 。 令人惊讶的事实(至少对我来说)是我没有做任何有大图像或大数据或类似的东西。 因为我只是测试,所以我使用了Volley来调用一个公共的天气API,我知道肯定的(在Postman选中的)只返回一个简单的JSON。 我怎么可能得到OutOfMemoryError 为了实施这次Volley呼叫,我实施了一个可能不正确的VolleySingleton ,不确定这一点。 我将在这里发布所有相关的代码: —> VolleySingleton.kt object VolleySingleton : Application(){ var requestQueue: RequestQueue? = null get() { if (requestQueue == null) { requestQueue = Volley.newRequestQueue(applicationContext) } return requestQueue } fun <T> addToRequestQueue(request: Request<T>) { requestQueue?.add(request) } } 然后就是使用VolleySingleton.tk的MainActivity.kt上的函数 fun callWeatherAPI(){ val request = StringRequest(Request.Method.GET,url, Response.Listener { response -> Log.d("API","RESPONSE: "+response) }, […]