<i id='k3Xhe'><tr id='k3Xhe'><dt id='k3Xhe'><q id='k3Xhe'><span id='k3Xhe'><b id='k3Xhe'><form id='k3Xhe'><ins id='k3Xhe'></ins><ul id='k3Xhe'></ul><sub id='k3Xhe'></sub></form><legend id='k3Xhe'></legend><bdo id='k3Xhe'><pre id='k3Xhe'><center id='k3Xhe'></center></pre></bdo></b><th id='k3Xhe'></th></span></q></dt></tr></i><div id='k3Xhe'><tfoot id='k3Xhe'></tfoot><dl id='k3Xhe'><fieldset id='k3Xhe'></fieldset></dl></div>
    <bdo id='k3Xhe'></bdo><ul id='k3Xhe'></ul>
  • <small id='k3Xhe'></small><noframes id='k3Xhe'>

    <legend id='k3Xhe'><style id='k3Xhe'><dir id='k3Xhe'><q id='k3Xhe'></q></dir></style></legend>
    <tfoot id='k3Xhe'></tfoot>

      1. 使用 Java URLConnection 关闭 Cookie

        Cookies turned off with Java URLConnection(使用 Java URLConnection 关闭 Cookie)

          <legend id='MuEJm'><style id='MuEJm'><dir id='MuEJm'><q id='MuEJm'></q></dir></style></legend>
          <i id='MuEJm'><tr id='MuEJm'><dt id='MuEJm'><q id='MuEJm'><span id='MuEJm'><b id='MuEJm'><form id='MuEJm'><ins id='MuEJm'></ins><ul id='MuEJm'></ul><sub id='MuEJm'></sub></form><legend id='MuEJm'></legend><bdo id='MuEJm'><pre id='MuEJm'><center id='MuEJm'></center></pre></bdo></b><th id='MuEJm'></th></span></q></dt></tr></i><div id='MuEJm'><tfoot id='MuEJm'></tfoot><dl id='MuEJm'><fieldset id='MuEJm'></fieldset></dl></div>
          • <small id='MuEJm'></small><noframes id='MuEJm'>

                  <tbody id='MuEJm'></tbody>
                • <bdo id='MuEJm'></bdo><ul id='MuEJm'></ul>

                • <tfoot id='MuEJm'></tfoot>
                • 本文介绍了使用 Java URLConnection 关闭 Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试向需要 cookie 的网页发出请求.我正在使用 HTTPUrlConnection,但响应总是回来说

                  I am trying to make a request to a webpage that requires cookies. I'm using HTTPUrlConnection, but the response always comes back saying

                  <div class="body"><p>Your browser's cookie functionality is turned off. Please turn it on.
                  

                  如何发出请求,使被查询的服务器认为我打开了 cookie.我的代码是这样的.

                  How can I make the request such that the queried server thinks I have cookies turned on. My code goes something like this.

                  private String readPage(String page) throws MalformedURLException {
                      try {
                          URL url = new URL(page);
                          HttpURLConnection uc = (HttpURLConnection) url.openConnection();
                          uc.connect();
                  
                          InputStream in = uc.getInputStream();
                          int v;
                          while( (v = in.read()) != -1){
                              sb.append((char)v);
                          }
                          in.close();
                          uc.disconnect();
                      } catch (IOException e){
                          e.printStackTrace();
                      }
                      return sb.toString();
                  }
                  

                  推荐答案

                  你需要在系统中添加一个CookieHandler来处理cookie.在 Java 6 之前,JRE 中没有 CookieHandler 实现,您必须自己编写.如果您使用的是 Java 6,则可以这样做,

                  You need to add a CookieHandler to the system for it handle cookie. Before Java 6, there is no CookieHandler implementation in the JRE, you have to write your own. If you are on Java 6, you can do this,

                    CookieHandler.setDefault(new CookieManager());
                  

                  URLConnection 的 cookie 处理真的很弱.它几乎不起作用.它不能正确处理所有 cookie 规则.如果您正在处理身份验证等敏感 cookie,则应使用 Apache HttpClient.

                  URLConnection's cookie handling is really weak. It barely works. It doesn't handle all the cookie rules correctly. You should use Apache HttpClient if you are dealing with sensitive cookies like authentication.

                  这篇关于使用 Java URLConnection 关闭 Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)

                • <i id='N8m1l'><tr id='N8m1l'><dt id='N8m1l'><q id='N8m1l'><span id='N8m1l'><b id='N8m1l'><form id='N8m1l'><ins id='N8m1l'></ins><ul id='N8m1l'></ul><sub id='N8m1l'></sub></form><legend id='N8m1l'></legend><bdo id='N8m1l'><pre id='N8m1l'><center id='N8m1l'></center></pre></bdo></b><th id='N8m1l'></th></span></q></dt></tr></i><div id='N8m1l'><tfoot id='N8m1l'></tfoot><dl id='N8m1l'><fieldset id='N8m1l'></fieldset></dl></div>

                    <legend id='N8m1l'><style id='N8m1l'><dir id='N8m1l'><q id='N8m1l'></q></dir></style></legend>
                      <bdo id='N8m1l'></bdo><ul id='N8m1l'></ul>
                        <tfoot id='N8m1l'></tfoot>
                            <tbody id='N8m1l'></tbody>

                            <small id='N8m1l'></small><noframes id='N8m1l'>