Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code call interface error http code 405 #3108

Closed
zengqinchris opened this issue Jul 1, 2020 · 1 comment
Closed

Code call interface error http code 405 #3108

zengqinchris opened this issue Jul 1, 2020 · 1 comment
Labels
question Further information is requested

Comments

@zengqinchris
Copy link

zengqinchris commented 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)");

        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)

@zengqinchris zengqinchris added the question Further information is requested label Jul 1, 2020
@samz406
Copy link
Contributor

samz406 commented Jul 1, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants