⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 httpsocket.java

📁 java反编译
💻 JAVA
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   HTTPSocket.java

package com.heaton.bot;

import java.io.*;
import java.net.*;

// Referenced classes of package com.heaton.bot:
//            HTTP, ByteList, HTTPException, SocketFactory, 
//            Log, AttributeList, Attribute, URLUtility

public class HTTPSocket extends HTTP
{

    public HTTPSocket()
    {
    }

    public synchronized void lowLevelSend(String url, String post)
        throws UnknownHostException, IOException
    {
        byte buffer[] = new byte[1024];
        int port = 80;
        boolean https = false;
        Socket socket = null;
        OutputStream out = null;
        InputStream in = null;
        try
        {
            URL u;
            if(url.toLowerCase().startsWith("https"))
            {
                url = "http" + url.substring(5);
                u = new URL(url);
                if(u.getPort() == -1)
                    port = 443;
                https = true;
            } else
            {
                u = new URL(url);
            }
            if(u.getPort() != -1)
                port = u.getPort();
            socket = SocketFactory.getSocket(u.getHost(), port, https);
            socket.setSoTimeout(timeout);
            out = socket.getOutputStream();
            in = socket.getInputStream();
            String command;
            if(post == null)
                command = "GET ";
            else
                command = "POST ";
            String file = u.getFile();
            if(file.length() == 0)
                file = "/";
            if(SocketFactory.useProxy())
            {
                addProxyAuthHeader();
                if(port != 80)
                    file = "http://" + u.getHost() + ":" + port + file;
                else
                    file = "http://" + u.getHost() + file;
            }
            command = command + file + " HTTP/1.0";
            SocketFactory.writeString(out, command);
            Log.log(3, "Request: " + command);
            if(post != null)
                clientHeaders.set("Content-Length", "" + post.length());
            clientHeaders.set("Host", u.getHost());
            int i = 0;
            StringBuffer headers = new StringBuffer();
            Attribute a;
            do
            {
                a = clientHeaders.get(i++);
                if(a != null)
                {
                    headers.append(a.getName());
                    headers.append(": ");
                    headers.append(a.getValue());
                    headers.append("\r\n");
                    Log.log(2, "Client Header:" + a.getName() + "=" + a.getValue());
                }
            } while(a != null);
            Log.log(1, "Writing client headers:" + headers.toString());
            if(headers.length() >= 0)
                out.write(headers.toString().getBytes());
            SocketFactory.writeString(out, "");
            if(post != null)
            {
                Log.log(2, "Socket Post(" + post.length() + " bytes):" + new String(post));
                out.write(post.getBytes());
            }
            header.setLength(0);
            int chars = 0;
            boolean done = false;
            while(!done) 
            {
                int ch = in.read();
                if(ch == -1)
                    done = true;
                switch(ch)
                {
                case 10: // '\n'
                    if(chars == 0)
                        done = true;
                    chars = 0;
                    break;

                default:
                    chars++;
                    break;

                case 13: // '\r'
                    break;
                }
                header.append((char)ch);
            }
            parseHeaders();
            Attribute acl = serverHeaders.get("Content-length");
            int contentLength = 0;
            try
            {
                if(acl != null)
                    contentLength = Integer.parseInt(acl.getValue());
            }
            catch(Exception e)
            {
                Log.logException("Bad value for content-length:", e);
            }
            int max;
            if(maxBodySize != -1)
                max = Math.min(maxBodySize, contentLength);
            else
                max = contentLength;
            if(max < 1)
                max = -1;
            ByteList byteList = new ByteList();
            byteList.read(in, max);
            body = byteList.detach();
            Log.log(1, "Socket Page Back:" + new String(body) + "\r\n");
            if(err >= 400 && err <= 599)
            {
                Log.log(4, "HTTP Exception:" + response);
                throw new HTTPException(response);
            }
        }
        finally
        {
            if(out != null)
                try
                {
                    out.close();
                }
                catch(Exception e) { }
            if(in != null)
                try
                {
                    in.close();
                }
                catch(Exception e) { }
            if(socket != null)
                try
                {
                    socket.close();
                }
                catch(Exception e) { }
        }
    }

    HTTP copy()
    {
        return new HTTPSocket();
    }

    protected void addProxyAuthHeader()
    {
        if(SocketFactory.getProxyUID() != null && SocketFactory.getProxyUID().length() > 0)
        {
            String hdr = SocketFactory.getProxyUID() + ":" + SocketFactory.getProxyPWD() != null ? SocketFactory.getProxyPWD() : "";
            String encode = URLUtility.base64Encode(hdr);
            clientHeaders.set("Proxy-Authorization", "Basic " + encode);
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -