0
私はHttpURLConnectionのを使用して、HTTP基本真偽を取得しようとしていますが、接続からの応答コードが200HTTP基本真偽 - アンドロイド - HttpURLConnectionの
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setDoInput(true);
urlConnection.setDoOutput(true); // automatically use POST method
/*Header Set Up, based on HTTP Basic Authentification Method*/
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
String basic = "Basic " + Base64.encodeToString(("******:******").getBytes(), Base64.NO_WRAP);
Log.d("TAG", basic);
urlConnection.setRequestProperty("Authorization", basic);
Log.d("TAG", urlConnection.toString());
Log.d("TAG", "connect..");
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int statusCode = urlConnection.getResponseCode();
/* 200 represents HTTP OK */
if (statusCode == 200) {
result = 1; // Successful
Log.e("TAG", "Connection Success");
}else{
result = 0; //"Failed to fetch data!";
Log.e("TAG", "Failed to fetch data!");
}
とモニターとは異なるためのsetRequestPropertyは、機能していないようです表示:
D/TAG: Basic aW50ZXJudGVzdDp0b2JwYW4zOTY3
D/TAG: com.android.okhttp.internal.http.HttpURLConnectionImpl: My URL
D/TAG: connect..
E/TAG: Failed to fetch data!
ありがとうございます!