簡體   English   中英

到Aruba托管的Java發布請求失敗

[英]Java post request to Aruba hosting fails

由於這個問題,我遇到了很大的麻煩。 我無法從Java客戶端獲取PHP API中的POST數據。 我僅在Aruba托管中遇到此問題,而在本地開發或其他托管站點中卻沒有

這是java請求:

urlParameters = "name=Jack";
    byte[] postData = urlParameters.getBytes(StandardCharsets.UTF_8);

    try {

        URL myurl = new URL(url);
        con = (HttpURLConnection) myurl.openConnection();

        con.setDoOutput(true);
        con.setRequestMethod("POST");
        con.setRequestProperty("User-Agent", "Java client");
        con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        con.setRequestProperty("Content-Length", String.valueOf(postData.length));
        try (DataOutputStream wr = new DataOutputStream(con.getOutputStream())) {
            wr.write(postData);
        }

        StringBuilder content;

        try (BufferedReader in = new BufferedReader(
                new InputStreamReader(con.getInputStream()))) {

            String line;
            content = new StringBuilder();

            while ((line = in.readLine()) != null) {
                content.append(line);
                content.append(System.lineSeparator());
            }
        }

        System.out.println(content.toString());

    }catch(MalformedURLException e){
        System.out.println("Error "+e);
    }catch(IOException e){
        System.out.println("Error "+e);
      }
    finally {

        con.disconnect();
    }

同樣在PHP中我得到:

if($_SERVER['REQUEST_METHOD'] === 'POST')  false
$entityBody = file_get_contents('php://input');  empty string

我也嘗試過更改php版本,但是什么也沒有...謝謝您的幫助!

使用Wireshark我得到了這個。 我不是專家,但我認為該請求已由代理重定向並變為GET

在此處輸入圖片說明

好的,我發現了另一個線索,即使使用html表單,它也行不通,但前提是我使用完整的網站路徑

<form method="POST" action="http://example.com/php/api.php"> doesn't work
<form method="POST" action="/php/api.php"> work

現在我認為這是一個許可問題,但我不知道怎么辦。

通過使用以下格式的地址URL來解決:“ www.exemple.com/page.php ”,而不是“ http://exemple.com/page.php ”或“ https://exemple.com/page.php ”。 可能是由於提供商的DNS設置

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM