java.io.IOException:服务器返回了URL的HTTP响应代码:400

java.io.IOException:服务器返回了URL的HTTP响应代码:400,java,proxy,ntlm,Java,Proxy,Ntlm,我正在开发一个线程java应用程序,它可以点击url发送sms消息 问题是我在NTLM代理服务器后面,我搜索了一天的大部分时间,尝试了许多解决方案,但没有成功。应用程序给出了标题错误,当我试图打印错误响应时,我发现它的错误页面来自代理服务器 这是密码 System.setProperty("java.net.useSystemProxies", "true"); System.setProperty("http.proxyHost", AUTH_PROXY

我正在开发一个线程java应用程序,它可以点击url发送sms消息
问题是我在NTLM代理服务器后面,我搜索了一天的大部分时间,尝试了许多解决方案,但没有成功。应用程序给出了标题错误,当我试图打印错误响应时,我发现它的错误页面来自代理服务器

这是密码

System.setProperty("java.net.useSystemProxies", "true");
                    System.setProperty("http.proxyHost", AUTH_PROXY");
                    System.setProperty("http.proxyPort", AUTH_PROXY_PORT);
                    System.setProperty("http.proxyUser", AUTH_USER);
                    System.setProperty("http.proxyPassword", AUTH_PASSWORD);

                    Authenticator.setDefault(
                              new Authenticator() {
                                public PasswordAuthentication getPasswordAuthentication() {
                                  return new PasswordAuthentication(AUTH_USER, AUTH_PASSWORD.toCharArray());
                                }
                              }
                            );

                     URL url = new URL(urlString);

                     HttpURLConnection httpConn =(HttpURLConnection)url.openConnection();
                     httpConn.setReadTimeout(10000);
                     String resp = getResponse(httpConn);
                     logger.info("urlString=" + urlString);
                     logger.info("Response=" + resp);
我得到了喘息的机会

private String getResponse(HttpURLConnection Conn) throws IOException {


        InputStream is;
        if (Conn.getResponseCode() >= 400) {
            is = Conn.getErrorStream();
        } else {
            is = Conn.getInputStream();
        }


        String response = "";
        byte buff[] = new byte[512];
        int b = 0;
        while ((b = is.read(buff, 0, buff.length)) != -1) {
            response += new String(buff, 0, b);

        }
        is.close();

        return response;
    }

非常感谢您的帮助经过多次尝试,我意识到上面的代码很好,我得到的400个错误是因为没有编码可能有空格的URL参数

刚用过

URLEncoder.encode(urlParameter,"UTF-8");
对于代码中的参数,空格解决了问题