通过创建HttpURLConnection发布数据时出现javascript错误

时间:2015-03-21 15:14:40

标签: java

我尝试使用HttpURLConnection连接到weblogic服务器。

以下是我的请求方法: -

  private void sendPost(String url, String postParams) throws Exception {

      URL obj = new URL(url);  
      conn = (HttpURLConnection) obj.openConnection();  


        conn.setUseCaches(false);
        conn.setRequestMethod("POST");
        conn.setRequestProperty("Host", "<IP-ADDRESS>:7001");
        conn.setRequestProperty("User-Agent", USER_AGENT);
        conn.setRequestProperty("Accept",
                "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
        conn.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
        conn.setRequestProperty("Accept-Encoding", "gzip, deflate");


        conn.setRequestProperty("Connection", "keep-alive");
        conn.setRequestProperty("Referer", "http://<IP-ADDRESS>:7001/console/login/LoginForm.jsp");
        conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        conn.setRequestProperty("Content-Length", Integer.toString(postParams.length()));




        if (cookies != null) {

            conn.addRequestProperty("Cookie", cookies.split(";", 1)[0]);

    }

        conn.setDoOutput(true);
        conn.setDoInput(true);


        // Send post request
        DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
        wr.writeBytes(postParams);
        wr.flush();
        wr.close();

        int responseCode = conn.getResponseCode();
        System.out.println("\nSending 'POST' request to URL : " + url);
        System.out.println("Post parameters : " + postParams);
        System.out.println("Response Code : " + responseCode);

    BufferedReader in = 
             new BufferedReader(new InputStreamReader(conn.getInputStream()));
    String inputLine;
    StringBuffer response = new StringBuffer();

    while ((inputLine = in.readLine()) != null) {
        response.append(inputLine);
    }
    in.close();


  }

在上面的代码中 postParams =“j_username = weblogic&amp; j_password = weblogic1&amp; j_character_encoding = UTF-8”; url =“http://IP-ADDRESS:7001/console/j_security_check”;

我无法登录WebLogic管理控制台。

获取错误: -

JavaScript是必需的。启用JavaScript以使用WebLogic管理控制台。

请帮助并告诉我如何启用java脚本?

0 个答案:

没有答案