我在向 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
提交
取消