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

📄 request.java

📁 How to get the java home dir.
💻 JAVA
字号:
/**
 version history
 1.5 2007-12-30 add alternate get and post methods that take a full URL.
 1.6 2008-01-14 add gzip option on read
 */
package com.mindprod.http;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/**
 * Like A StringBuilder but encodes CGI pairs for GET or POST.  Not normally needed. get, post, probe etc
 * all have parameter building option built-in.
 *
 * @author Roedy Green
 * @version 1.9 2008-08-22 support accept-charset, accept-encoding and accept-language.  Fix bugs in gzip support.
 * @since 2003-05-26
 */
@SuppressWarnings( { "WeakerAccess" } )
public final class Request
    {
    /**
     * used to build the pairs
     */
    private final StringBuilder sb;

    // -------------------------- PUBLIC INSTANCE  METHODS --------------------------
    // ideally would extend StringBuilder, but it is final.
    /**
     * constructor
     *
     * @param size estimated size of result string.
     */
    public Request( int size )
        {
        this.sb = new StringBuilder( size );
        }

    /**
     * append a parm=value pair of CGI parameters, encoding them with URL encoding, xxx=yyy&aaa=bbb etc.
     *
     * @param name  parameter name
     * @param value parameter value
     */
    @SuppressWarnings( { "UnusedDeclaration" } )
    public void appendCGIPair( String name, String value )
        {
        if ( sb.length() != 0 )
            {
            // separates pairs
            sb.append( '&' );
            }
        try
            {
            sb.append( URLEncoder.encode( name, "UTF-8" ) );
            sb.append( '=' );
            sb.append( URLEncoder.encode( value, "UTF-8" ) );
            }
        catch ( UnsupportedEncodingException e )
            {
            throw new IllegalArgumentException( "UTF-8 encoding support missing" );
            }
        }

    /**
     * get request as an a URL-encoded String.
     *
     * @return result CGI request string.
     */
    public String toString()
        {
        return sb.toString();
        }
    }

⌨️ 快捷键说明

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