0

I use the volley library to execute the POST method, but I get the following error: Unresolved reference: entrySet.

How can I solve this?

Here is my code:

Kotlin

   @Throws(AuthFailureError::class)
        override fun getBody(): ByteArray? {           

            val params = params
            if (params != null && params.size > 0) {
                 return encoderParameters(params, paramsEncoding)
            }
            return null
        }

      fun encoderParameters(params: HashMap<String, String>, paramsEncoding: String): ByteArray { 
           val encodedParams = StringBuilder()

            try {
                for (entry in params.entrySet()) {
                    encodedParams.append(URLEncoder.encode(entry.key), paramsEncoding)
                            encodedParams . append ('=')
                            encodedParams . append (URLEncoder.encode(entry.value, paramsEncoding))
                            encodedParams . append ('&')
                }

                return encodedParams.toString().toByteArray(charset(paramsEncoding))

            }catch (e: UnsupportedEncodingException){
                throw RuntimeException("Encoding not supported: $paramsEncoding", e)
            }
        }
4

1 回答 1

0

Convert

            for (entry in params.entrySet()) {
                encodedParams.append(URLEncoder.encode(entry.key), paramsEncoding)
                        encodedParams . append ('=')
                        encodedParams . append (URLEncoder.encode(entry.value, paramsEncoding))
                        encodedParams . append ('&')
            }

into

            for ((key, value) in params) {
                encodedParams.append(URLEncoder.encode(key), paramsEncoding)
                        encodedParams . append ('=')
                        encodedParams . append (URLEncoder.encode(value, paramsEncoding))
                        encodedParams . append ('&')
            }

should work.

于 2018-05-03T17:30:12.370 回答