Tag: httpurlconnection

Android与Kotlin – 如何使用HttpUrlConnection

我试图从一个AsyncTask的url获取数据,但是在创建HttpUrlConnection的新实例时出现HttpUrlConnection 。 在Java上是这样的 URL url = new URL(“http://www.android.com/”); HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); try { InputStream in = new BufferedInputStream(urlConnection.getInputStream()); readStream(in); finally { urlConnection.disconnect(); } 但我不断收到如下所示的错误。 class GetWeatherTask : AsyncTast() { override fun doInBackground(vararg params: Void?): Void? { val httpClient = HttpURLConnection(); return null } override fun onPreExecute() { super.onPreExecute() } override fun onPostExecute(result: Void?) […]

Android与Kotlin – 如何使用HttpUrlConnection

我试图从一个AsyncTask的url中获取数据,但是在创建HttpUrlConnection的新实例时出现HttpUrlConnection 。 在Java上是这样的 URL url = new URL("http://www.android.com/"); HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); try { InputStream in = new BufferedInputStream(urlConnection.getInputStream()); readStream(in); finally { urlConnection.disconnect(); } 但我不断收到如下所示的错误。 class GetWeatherTask : AsyncTast<Void, Void, Void>() { override fun doInBackground(vararg params: Void?): Void? { val httpClient = HttpURLConnection(); return null } override fun onPreExecute() { super.onPreExecute() } override fun […]

握手使用okHttp失败,但使用HttpURLConnection工作

我试图发送请求到服务器(发送请求测试,实际上我需要发送一个请求到同一台服务器。如果得到工作,发布将工作) 链接到服务器是https://bits-bosm.org/2017/registrations/signup/ 问题是当我发送请求使用okHttp,我得到一个失败的回应说握手失败。 这里是我使用的代码发送请求使用okHttp(在kotlin) val request = Request.Builder() .url("https://bits-bosm.org/2017/registrations/signup/") .build() okHttpClient.newCall(request).enqueue(object : Callback { override fun onFailure(call: Call?, e: IOException?) { val mMessage = e?.message?.toString() Log.w("failure Response", mMessage) } override fun onResponse(call: Call?, response: Response?) { val mMessage = response?.body()?.string() Log.e("Message", mMessage) } }) 但是,如果我使用HttpUrlConnection发送获取请求到同一台服务器,我得到的答复。 这里是相同的代码(Java) private static final String USER_AGENT = "Mozilla/5.0"; private static […]