ไม่อนุญาตให้ใช้วิธี 405 POST อย่างไรก็ตาม อนุญาต

ฉันกำลังพยายามส่ง POST ไปยังบริการบางอย่าง ภายในเนื้อหาคำขอจะมี XML ฉันได้ลองทำผ่าน SOAP UI แล้ว - ใช้งานได้ - เพียงแค่ใส่ข้อความ XML เข้าไปในข้อมูลร่างกาย ผ่าน Jmeter - มันใช้งานได้ ผ่านโค้ดจาวาของฉันเอง มันส่งคืนฉัน 405 - ไม่อนุญาตให้ใช้วิธีการ ฉันได้รับ 405 ใน Jmeter หรือ SOAP UI หากเพียงฉันเปลี่ยนวิธีการเป็น GET

นี่คือรหัสของฉัน โดยที่วิธี POST ถูกตั้งค่าไว้อย่างแน่นอน ฉันไม่รู้ว่ามีอะไรผิดปกติ

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 แหล่งที่มา
comment
อาจเปิดใช้งานการป้องกัน CSRF อยู่หรือไม่   -  person Nikolai Shevchenko    schedule 08.06.2018


คำตอบ (1)


แก้ไขแล้ว ปัญหาอยู่ที่ท้ายบรรทัดนี้:

สตริง soapEndpointUrl = "https://some.com/test";

ควรมีเครื่องหมายทับใน URL

person Catherin    schedule 09.06.2018