zengqinchris opened a new issue #3108:
URL: https://github.com/apache/incubator-dolphinscheduler/issues/3108
`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://bigdata-1.wumii.net:15681/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)
`
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]