java apache HC BasicHttpEntityEnclosingRequest vs BasicHttpRequest [英] java apache HC BasicHttpEntityEnclosingRequest vs BasicHttpRequest

查看:352
本文介绍了java apache HC BasicHttpEntityEnclosingRequest vs BasicHttpRequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Making a class that takes instructions (steps) from a data source and automates few HC (http://hc.apache.org Apache Http Client) actions.

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

Want to be able to carry out HTTP post, get and direct (like sending a JSON or XML/ soap message to a web server) calls.

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

Confused about when to use BasicHttpEntityEnclosingRequest vs BasicHttpReques what is the enclosing? Right now I have steps to init the context, provide param values, the URL, method etc when i want to submit this is what I'm doing:

        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?

Question : use one or the other or have another attribute for enclosing or regular 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 )是否合法以附上请求正文有待商榷。

HTTP specification clearly defines only POST and PUT as methods which can enclose a request content body. Whether or not it is legal for other methods such as GET or HEAD to enclose a request body is subject to debate.

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

HttpCore follows strict interpretation of the HTTP specification and represent regular requests as HttpRequest which does not provide a method to set a content body. For methods such as PUT and POST it provides extended HttpEntityEnclosingRequest with extra methods for request entity manipulations.

这篇关于java apache HC BasicHttpEntityEnclosingRequest vs BasicHttpRequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆