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

📄 httprequest.java

📁 国外的j2me播放器软件
💻 JAVA
字号:
package no.auc.one.portableplayer.communication.upnphosting;

import java.util.Hashtable;
import javax.microedition.io.SocketConnection;

/**
 * Information about a HTTP request.
 */
public final class HttpRequest {
    private final static int REQUEST_METHOD_MIN         = 0;
    public final static int REQUEST_METHOD_GET          = 0;
    public final static int REQUEST_METHOD_POST         = 1;
    public final static int REQUEST_METHOD_SUBSCRIBE    = 2;
    public final static int REQUEST_METHOD_UNSUBSCRIBE  = 3;
    public final static int REQUEST_METHOD_OPTIONS      = 4;
    private final static int REQUEST_METHOD_MAX         = 
        REQUEST_METHOD_OPTIONS;
            
    private int requestMethod;
    private String requestUri;
    private String httpVersion;
    private String body;
    private Hashtable headers = new Hashtable(5);
    private SocketConnection sc;

    /**
     * Set the request method of this request.
     *
     * Must be one of the REQUEST_METHOD constants.
     */
    public void setRequestMethod(int reqMethod) {
        if (reqMethod < REQUEST_METHOD_MIN && 
            reqMethod > REQUEST_METHOD_MAX) 
        {
            throw new IllegalArgumentException(
                "Request method number must be one of the REQUEST_METHOD " + 
                "constants. The specified number (" + reqMethod + ") was " + 
                "out of range([" + REQUEST_METHOD_MIN + ", " + 
                REQUEST_METHOD_MAX + "]).");
        }

        requestMethod = reqMethod;
    }

    /**
     * Returns the request method.
     *
     * See REQUEST_METHOD constants for what the number means.
     */
    public int getRequestMethod() {
        return requestMethod;
    }
    
    /**
     * Set request uri of this request.
     *
     * Note that this method does NOT check if the supplied URI is a valid URI.
     */
    public void setRequestUri(String uri) {
        requestUri = uri;
    }

    /**
     * Get request uri of this request.
     */
    public String getRequestUri() {
        return requestUri;
    }

    /**
     * Set the HTTP version supported by the client which sent this request.
     *
     * The format of this version string should be:
     * 1*DIGIT "." 1*DIGIT
     * 
     * Examples of valid strings are "1.1", "2.3", and "1.0".
     *
     * See also section 3.1 of RFC2616.
     *
     * This method does NOT validate the version argument.
     */
    public void setHttpVersion(String version) {
        httpVersion = version;
    }
    
    /**
     * Get the HTTP version supported by the client which sent this request.
     */
    public String getHttpVersion() {
        return httpVersion;
    }
    
    /**
     * Set the body of this request.
     */
    public void setBody(String body) {
        this.body = body;
    }

    /**
     * Get the body of this request.
     */
    public String getBody() {
        return body;
    }
    
    /**
     * Set a header of this request.
     */
    public void setHeader(String name, String value) {
        headers.put(name, value);
    }
    
    /**
     * Get header value.
     */
    public String getHeader(String name) {
        return (String)headers.get(name);
    }

    /**
     * Is header available?
     */
    public boolean hasHeader(String name) {
        return headers.containsKey(name);
    }
    
    /**
     * Set connection for communication with the client.
     */
    public void setSocketConnection(SocketConnection sc) {
        this.sc = sc;
    }

    /**
     * Get the connection for communication with the client which sent this 
     * request.
     */
    public SocketConnection getSocketConnection() {
        return sc;
    }
}

⌨️ 快捷键说明

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