创建一个从数据源获取指令(步骤)的类,并自动执行一些操作(http://hc.apache.orgApache Http客户端)操作。
希望能够执行HTTP post、get和direct(比如向web服务器发送JSON或XML/soap消息)调用。
困惑于何时使用BasicHttpEntityEnclosingRequest与BasicHttpRequest什么是封装?现在,当我想要提交时,我有初始化上下文、提供参数值、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
HTTP规范明确定义只有POST
和PUT
可以包含请求内容体的方法。其他方法,如GET
或HEAD
封装请求主体是否合法,还有待讨论。
HttpCore遵循对HTTP规范的严格解释,并将常规请求表示为HttpRequest
,它不提供设置内容正文的方法。对于PUT
和POST
等方法,它提供了扩展的HttpEntityEnclosingRequest
以及用于请求实体操作的额外方法。