JSON data and SLIM

Good evening,

In my project, I have middleware.php in the same directory as container.php.

// construction de l'application $app
    App::class => function (ContainerInterface $container) {
        $app = AppFactory::createFromContainer($container);

        // Configuration de le chemin de la base
        $app->setBasePath('/soignemoi-web'); //https://www.slimframework.com/docs/v4/start/web-servers.html

        $app->addBodyParsingMiddleware(); //Donnees JSON sur serveur WEB

        // Register routes
        (require __DIR__ . '/routes.php')($app);

        //Register middleware
        (require __DIR__ . '/middleware.php')($app);

        return $app;



use Slim\App;

return function (App $app) {
    // Parse json, form data and xml

    // Add the Slim built-in routing middleware

    // Handle exceptions
    $app->addErrorMiddleware(true, true, true);

When I use Postman, the JSON data is sent to my database. However, the web page appears in POSTMAN.
I created a mobile application in Java that communicates with my database, but it doesn’t work:

private void transfertJSON() throws IOException {

        URL url = new URL("");
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();

        // Convertir la HashMap en JSON
        String stringJSON = new Gson().toJson(tableauPrescription);

        // Configurer la connexion
        conn.setRequestProperty("Content-Type", "application/json");

        // Écrire les données JSON dans le flux de sortie
        try(OutputStream os = conn.getOutputStream()) {
            byte[] input = stringJSON.getBytes("utf-8");
            os.write(input, 0, input.length);
        }catch (Exception e) {
            Log.e(TAG, "erreur d'écriture: " + e.getMessage(), e);

        // Lire la réponse
        int responseCode = conn.getResponseCode();
        Log.d(TAG, "code de la réponse: " + responseCode);
        if (responseCode == HttpURLConnection.HTTP_OK) {
            Log.d(TAG, "Envoi de données réussi.");
        } else {
            Log.e(TAG, "Envoi de données échoué. Code de la réponse: " + responseCode);

Thank you for your help.


erreur d'écriture: Cleartext HTTP traffic to not permitted
java.io.IOException: Cleartext HTTP traffic to not permitted
at com.android.okhttp.HttpHandler$CleartextURLFilter.checkURLPermitted(HttpHandler.java:127)

Http is not permitted. I perhaps find a solution.

It works. I had two problems:

  • The HTTP interdiction (not to be used in production)
  • My application wanted to run on the main thread of Android. It’s forbidden.

For the interdiction, I made an XML file named network_security_config.xml in the app/res/xml folder:

    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true"></domain>

and in app/manifests/AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    <uses-permission android:name="android.permission.INTERNET"/>


For the threads, I use the Retrofit method. It’s long to explain here. ChatGPT4 knows how to do it.

Good afternoon.

It’s strange. With Android Studio, the web page also appears in the Logcat console.