无法使用标题X-Content-Type-Options解码内容:nosniff java

时间:2013-05-08 18:10:54

标签: java response decode

这是我的代码来获取capcha html但我得到的答案完全不可理解,有人可以帮助我吗?

当我运行下面的代码时,我得到的输出以不同的字符打印。但是工作得很完美,并在其他网站上提供了一个HTML字符串。

程序:

public static void main(String[] args0) {
String responseSecure = "http://www.google.com/recaptcha/api/challenge?k=6Lel4tASAAAAAIGYoTJ_0mbM4hyAEiTiRqGtN36p";
        if(responseSecure != null) {
            capchaURL(responseSecure, "", cookie);
}
}
public static String capchaURL(String targetURL, String urlParameters, String cookie) {
            URL url;
            HttpURLConnection connection = null;
            OutputStream os = null;
            try {
                // Create connection
                url = new URL(targetURL);
                connection = (HttpURLConnection) url.openConnection();
                connection.setRequestMethod("GET");
                connection.setRequestProperty("Acccept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
                connection.setRequestProperty("Accept-Encoding", "gzip, deflate");
                connection.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
                connection.setRequestProperty("Connection", "keep-alive");
                connection.setRequestProperty("Host", "www.google.com");
                connection.setRequestProperty("Cookie", "PREF=ID=ac09d0854b946b65:U=1b03f75feea0e6f1:FF=0:LD=en:TM=1364821605:LM=1365085352:GM=1:S=D_Zqsff7LMNBjfxq; NID=67=AUL9HiZ8O-JXtyZne2WCpPNlY-NGg_-H3tj5OeILwpfCSLzBUVLfQA9nms1952fCodeI-XJKUS2sueQdWeHISovlRD51gaXI7hpXNIJfzyEk83pajknx7oyxLcavAMtsKYLjqQnlTbKOGDWzclLYZ-PifQBVN_SwbBs-xK9wJVLiODsHcxxHVht75qs0rVyd5qe-hxvlwG8X_o7ooh1TTOJW29nmVFPUvQkdwrXhRuLtATsPDVAw2fRWdGbqTSLQfVXFcBR1wg; SID=DQAAAHEBAABvoK4gNk2H5OG5bDvfXn67e7tjeOCVCvxa-w8FQ8mgwL7u2SoAnOMFI2JmptQGZoaL0-ndqtWRRfT0vHaFrmLwoqkL9RLhUxN9IROa93mJ9NZK666Z8xIyAv6mycvTU4A4mKqUrzncMp_pNyywjzp_-lblrmNTlgJ3h3Kf3aB2lk0QAtocwby08YgJxBhjRHy_iA17BwIHZ26LJi-DICVitKHKlCbeV6N7MuBg4JeYFmLa3WB6mKbpbrGbwyUBj1dM8x7xVafV5l97bIm1STiENQO87uzIXgpss76PsLHrOqBDfhi0RbibzW2O5QQDnlZj_bRFgeg5jqc-br5vLLXy5VRPo9n048XPUMG0rm20q_YUnb-eIcGPJbFGELYxyYrkaKNAxxMPfagv7u86BIqJ72MIafDScLCckIZ2m6HDqFNosVSAgRPFr0LlooInlrRBtQlIaQMnkgRuh-DYOLyiLsRwN-oZA5MugoUXZNgElFlkgRBASX3kveolvNDhh5w; HSID=AAqchMiifwHL5MqCX; APISID=JwNfet67hflZElbh/AXel3W1clUAzyV7OC");
                connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:20.0) Gecko/20100101 Firefox/20.0");
                connection.setUseCaches(false);
                connection.setDoInput(true);
                connection.setDoOutput(true);
                // Send request
                DataOutputStream wr = new DataOutputStream(
                        connection.getOutputStream());
                System.out.println(connection.getContentType());
                wr.writeBytes(urlParameters);
                wr.flush();
                wr.close();

                // Get Response
                InputStream is = connection.getInputStream();

                /*os = new FileOutputStream(new File("C:/Users/Vinoth Kannah MP/Desktop/file.xml"));
                int read = 0;
                byte[] bytes = new byte[1024];

                while ((read = is.read(bytes)) != -1) {
                    os.write(bytes, 0, read);
                }
                os.close();*/

                BufferedReader rd = new BufferedReader(new InputStreamReader(is));
                String line;
                StringBuffer response = new StringBuffer();
                while ((line = rd.readLine()) != null) {
                    response.append(line);
                    response.append('\r');
                }
                /*BASE64Decoder decoder = new BASE64Decoder();
                byte[] decodedBytes = decoder.decodeBuffer(encodedBytes);*/
                System.out.println(StringEscapeUtils.escapeHtml(response.toString()));
                return "";
            } catch (Exception e) {
                e.printStackTrace();
                return null;

            } finally {

                if (connection != null) {
                    connection.disconnect();
                }
            }
        }

输出:

‹      ]R]sš@}çW0¾ÐŽ0X‚ĨŸ˜µÍ³Â
‹»Ë‡vòß‹†¶ÓÞ·{îž3çÜ»B ¨è@dÜ?€Ë‡âHü)ˆM1Ô4¢¤¿@<à¦k^k1{#[ÛS“÷At6'h‹œ|ÆWšžI_n4ÊqÃ:ÌàÐcÓð&¦jæÜöö»PÕ°?{Ö++ç»ù®Xº–µÝl¿j)óK½´^ŠñÀHÞú÷ɸoÛqmŸ›FNM?yp·HÓÓV»xp‡½ábr\3ÃâìuÚ3u7Φ‡~ô×(˜SgFÇ®P±îÕ&?/?‰›9CwjEÞ|½Úx{-¦1ú®®v›éÝ>ƒêéÉØèz~œŒ?E›1¥>¡úüߘ%!I‚ÒЃ”z?Û²n½—@ÆÀÇZœAZÂÛÈóìAQªª’CBBeŸ$
ý}dHiI¤á•Óà(?¤¸Úéª*¼?
B@ü"?)—+Ú\ñ“ôÄ|*u%”q‘Ÿ38êpXs%%h
ÚY3¦þ¨#‰Ýÿ>„ܺìŠRÌþZ’cÖy~Rþ?KŸ…_º¡¢P

0 个答案:

没有答案