Metode 405 tidak diperbolehkan POST, namun diperbolehkan

Saya mencoba mengirim POST ke beberapa layanan. Di dalam badan permintaan ada XML. Saya sudah mencoba melakukannya melalui SOAP UI - berhasil - cukup masukkan data tubuh teks XML. Melalui Jmeter - berhasil. melalui kode Java saya sendiri, ia mengembalikan saya 405 - metode tidak diizinkan. Saya mendapatkan 405 di Jmeter atau SOAP UI kalau saja saya mengubah metode menjadi GET.

Jadi inilah kode saya, di mana metode POST sudah pasti diatur. Saya tidak tahu apa yang salah.

public static void main(String args[]) {
    String soapEndpointUrl = "https://some.com/test";
    callSoapBankService(soapEndpointUrl);
}

private static void callSoapBankService(String soapEndpointUrl) {
    try {

        HttpsURLConnection httpsConnection = null;
        // Open HTTPS connection
        URL url = new URL(soapEndpointUrl);
        httpsConnection = (HttpsURLConnection) url.openConnection();
        // Connect
        httpsConnection.setRequestMethod("POST");
        httpsConnection.setDoInput(true);
        httpsConnection.setDoOutput(true);
        httpsConnection.setRequestProperty("SOAPAction", "");
        httpsConnection.setRequestProperty("Connection", "keep-alive");
        httpsConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        httpsConnection.setRequestProperty("Content-Length", "397");
        httpsConnection.setRequestProperty("Host", "some.com");
        httpsConnection.setRequestProperty("User-Agent", "Apache-HttpClient/4.1.1 (java 1.5)");
        DataOutputStream output = new DataOutputStream(httpsConnection.getOutputStream());
            output.writeBytes("<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ws=\"http://some.com/\">\n" +
                    "                <SOAP-ENV:Header/>\n" +
                    "                <SOAP-ENV:Body>\n" +
                    "                    <ws:getDocument>\n" +
                    "                        <beginDate>2018-02-09</beginDate>\n" +
                    "                        <endDate>2018-02-10</endDate>\n" +
                    "                    </ws:getDocument>\n" +
                    "                </SOAP-ENV:Body>\n" +
                    "             </SOAP-ENV:Envelope>");
         output.flush();
         output.close();
         DataInputStream input = new DataInputStream(httpsConnection.getInputStream());
         for( int c = input.read(); c != -1; c = input.read() )
         System.out.print( (char)c );
         input.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
   }

person Catherin    schedule 08.06.2018    source sumber
comment
Mungkin perlindungan CSRF diaktifkan?   -  person Nikolai Shevchenko    schedule 08.06.2018


Jawaban (1)


Terpecahkan. Masalahnya ada di akhir baris ini:

String sabunEndpointUrl = "https://some.com/test";

Harus ada garis miring di URL

person Catherin    schedule 09.06.2018