How to allow all types of HTTP and HTTPS network connections in Android 9 (Pie)?
Hello everyone! I'm new to Android development in Kotlin, and I've encountered a problem with network requests on Android 9 (Pie). In my app, I'm making a simple GET request to an API that works over HTTP (not HTTPS). Here's the simplified code:
```kotlin
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
Thread {
try {
val url = URL("http://example.com/api/data")
val connection = url.openConnection() as HttpURLConnection
connection.requestMethod = "GET"
val response = connection.inputStream.bufferedReader().readText()
Log.d("Network", "Response: $response")
```
No answers yet.
Log in to leave an answer
Blogs
HTTP client in TypeScript: making requests correctly: from A to Z
Constructors in Go: Best Practices 2025 the Docs Don't Tell You About
How to Get HTTP Response as a String in Go: Best Practices 2025
Substring Search in C++: From Naivety to Performance