我在向 nifi 發送簡單的 PUT 請求時遇到問題,基本上我想用 java 代碼啟動一個 nifi 處理器。錯誤消息 - 服務器返回 HTTP 響應代碼:URL 為 405:http://localhost:8080/nifi-api/processors/我應該采取什么步驟來解決這個 405 問題?nifi api 網站提供了有關 rest api 的高級文檔,但沒有關于如何使用 Java 向 NiFi 發出正確 PUT 請求的指南。import java.io.BufferedReader;import java.io.DataOutputStream;import java.io.InputStreamReader;import java.net.HttpURLConnection;import java.net.URL;import javax.net.ssl.HttpsURLConnection;public class HttpURLConnectionExample { private final String USER_AGENT = "Mozilla/5.0"; public static void main(String[] args) throws Exception { HttpURLConnectionExample http = new HttpURLConnectionExample(); System.out.println("\nTesting 2 - Send Http POST request"); http.sendPut(); } // HTTP PUT request private void sendPut() throws Exception { String url = "http://localhost:8080/nifi-api/processors/"; URL obj = new URL(url); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); //add reuqest header con.setRequestMethod("PUT"); con.setRequestProperty("Content-Type", "application/json"); con.setRequestProperty("Accept", "application/json"); con.setRequestProperty("text/javascript", "*/*"); String urlParameters = "{\r\n" + " \"status\": {\r\n" + " \"runStatus\": \"RUNNING\"\r\n" + " },\r\n" + " \"component\": {\r\n" + " \"state\": \"RUNNING\",\r\n" + " \"id\": \"749b3133-0162-1000-9acc-f384457b160c\"\r\n" + " },\r\n" + " \"id\": \"749b3133-0162-1000-9acc-f384457b160c\",\r\n" + " \"revisions\": {\r\n" + " \"version\": 1,\r\n" + " \"clientId\": \"550c4b84-0165-1000-37be-724ed17b5329\"\r\n" + "}\r\n" + " "; }}
添加回答
舉報
0/150
提交
取消