You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`public static String httpRequestUtils(String url, String params, String requestMethod) {
PrintWriter out = null;
BufferedReader in = null;
StringBuilder result = new StringBuilder();
try {
URL reqUrl = new URL(url);
// 建立连接
HttpURLConnection conn = (HttpURLConnection)reqUrl.openConnection();
//设置请求头
conn.setRequestProperty("Content-Type", "application/json;charset=utf-8");
conn.setRequestProperty("token", "11111111111111111111");
// conn.setRequestProperty("connection", "Keep-Alive");
// conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");
conn.setDoOutput(true); //设置为true才可以使用conn.getOutputStream().write()
conn.setDoInput(true); //可以使用conn.getInputStream().read();
conn.setRequestMethod(requestMethod);
if (!"".equals(params)) {
//写入参数
out = new PrintWriter(conn.getOutputStream());
//设置参数,可以直接写&参数,也可以直接传入拼接好的
out.print(params);
// flush输出流的缓冲
out.flush();
}
// 定义BufferedReader输入流来读取URL的响应
in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
String line = in.readLine();
while (line != null) {
result.append(line);
line = in.readLine();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (out != null) {
out.close();
}
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return result.toString();
}
public static void main(String[] args) {
String str = httpRequestUtils("http://xxxxxxx/dolphinscheduler/projects/online-test/process/list","pageNo=1&pageSize=50","GET");
System.out.println(str);
}
`
报错 java.io.IOException: Server returned HTTP response code: 405 for URL: http://xxxxxxxxxxxxx/dolphinscheduler/projects/online-test/process/list at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1900) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1498) at com.wumii.data.platform.manager.service.meta.SchedulerWorkflowService.httpRequestUtils(SchedulerWorkflowService.java:104) at com.wumii.data.platform.manager.service.meta.SchedulerWorkflowService.main(SchedulerWorkflowService.java:129)
The text was updated successfully, but these errors were encountered:
405 Method Not Allowed ,so. Please use postman to call the interface first. If it is correct, it means that there is a problem with the value of your calling method. Please check the method call parameters
samz406
changed the title
代码调用接口报错 405
Code call interface error http code 405
Jul 1, 2020
`public static String httpRequestUtils(String url, String params, String requestMethod) {
PrintWriter out = null;
BufferedReader in = null;
StringBuilder result = new StringBuilder();
try {
URL reqUrl = new URL(url);
// 建立连接
HttpURLConnection conn = (HttpURLConnection)reqUrl.openConnection();
//设置请求头
conn.setRequestProperty("Content-Type", "application/json;charset=utf-8");
conn.setRequestProperty("token", "11111111111111111111");
// conn.setRequestProperty("connection", "Keep-Alive");
// conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");
`
报错
java.io.IOException: Server returned HTTP response code: 405 for URL: http://xxxxxxxxxxxxx/dolphinscheduler/projects/online-test/process/list at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1900) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1498) at com.wumii.data.platform.manager.service.meta.SchedulerWorkflowService.httpRequestUtils(SchedulerWorkflowService.java:104) at com.wumii.data.platform.manager.service.meta.SchedulerWorkflowService.main(SchedulerWorkflowService.java:129)
The text was updated successfully, but these errors were encountered: