JSON-POST-Anforderung kann in PHP nicht empfangen werden

Ich übergebe ein JOSN-Objekt von Java an PHP. Ich benutze JDK 1.8 Ang WAMP Server. Unten ist der Java-Code.

import java.io.IOException;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.json.simple.JSONObject;

/**
 *
 * @author PReeeT Dash
 */
public class FromJava 
{
    public static void main(String[] args) throws IOException
    {
        JSONObject json = new JSONObject();
        json.put("someKey", "someValue");    

        CloseableHttpClient httpClient = HttpClientBuilder.create().build();

        try 
        {
            HttpPost request = new HttpPost("http://localhost/PGP/JSONReq/tophp.php");
            StringEntity params = new StringEntity(json.toString());
            request.addHeader("content-type", "application/json");
            request.setEntity(params);
            httpClient.execute(request);
        // handle response here...
        } catch (Exception ex) 
        {
            System.out.println("Error: Cannot Estabilish Connection");        
        } 
        finally 
        {
            httpClient.close();
        }
    }    
}

PHP-Skript:

$data = json_decode(file_get_contents("php://input"));
echo($data);

Wenn ich die PHP-Datei starte, wird immer eine leere Seite angezeigt. Kann mir bitte jemand helfen zu verstehen, warum es nicht funktioniert.

Wenn ich den folgenden PHP-Code ausführe, wird immer die else-Bedingung ausgeführt.

if ($_SERVER['REQUEST_METHOD'] == 'POST')
    {
        $data = json_decode(file_get_contents("php://input"));
        echo($data);
    }
    else
    {
        echo "XXXXXX";
    } 

Antworten auf die Frage(4)

Ihre Antwort auf die Frage