1

创建一个从数据源获取指令(步骤)并自动执行少量 HC(http://hc.apache.org Apache Http Client)操作的类。

希望能够执行 HTTP post、get 和direct(如向 Web 服务器发送 JSON 或 XML/soap 消息)调用。

对何时使用 BasicHttpEntityEnclosureRequest 与 BasicHttpReques 感到困惑,什么是封闭的?现在我有步骤来初始化上下文,提供参数值,URL,方法等,当我想提交这就是我正在做的事情:

        HttpPost httpost = null;//todo correct method
        //HttpEntity resp = this.httpclient.e

        HttpEntityEnclosingRequest reqEntity1 = null;//use this
        HttpRequest reqEntity = new BasicHttpRequest(method, urls, httpVer );//or this?
        URL url = new URL(urls);
        String hostNm = url.getHost();
        int port = url.getPort();
        String sche = url.getProtocol();
        logger.info("scheme/ proto :" + sche);
        HttpHost  httpHost = new HttpHost (hostNm, port, sche);
        response = this.httpclient.execute(httpHost, reqEntity, localContext);

问题:使用一个或另一个或有另一个属性来封闭或常规 HttpRequest?

http://hc.apache.org/httpcomponents-core-ga/httpcore/apidocs/org/apache/http/HttpRequest.html

http://hc.apache.org/httpcomponents-core-ga/httpcore/apidocs/org/apache/http/message/BasicHttpRequest.html

http://hc.apache.org/httpcomponents-core-ga/httpcore/apidocs/org/apache/http/HttpEntityEnclosingRequest.html

4

1 回答 1

2

HTTP 规范仅明确定义了可以包含请求内容主体的方法POSTPUT其他方法(例如附上请求主体)是否合法还有待商榷GETHEAD

HttpCore 遵循对 HTTP 规范的严格解释,并将常规请求表示为HttpRequest不提供设置内容主体的方法。对于诸如PUT和之类的方法,它为请求实体操作POST提供了额外的扩展方法。HttpEntityEnclosingRequest

于 2013-08-25T15:45:57.373 回答