`
卡拉阿风
  • 浏览: 99541 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

httpclient notes

阅读更多

http提交form数据参考:The enctype attribute of the FORM element specifies the content type used to encode the form data set for submission to the server. User agents must support the content types listed below. Behavior for other content types is unspecified.

http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.1

 

http post数据的时候还需要考虑无key的情况,所以requst方法函数在RequestMothod为POST的时候,需要对传入参数加个判断进行处理

 

《httpclient-tutorial-simplified-chinese》1.3.4 请求重试处理:为了开启自定义异常恢复机制,应该提供一个HttpRequestRetryHandler接口的实现。

import java.io.IOException;

import javax.net.ssl.SSLHandshakeException;

import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpRequest;
import org.apache.http.NoHttpResponseException;
import org.apache.http.protocol.ExecutionContext;
import org.apache.http.protocol.HttpContext;

public class HttpRequestRetryHandler implements
        org.apache.http.client.HttpRequestRetryHandler {
        
        int _retries;
        
        public HttpRequestRetryHandler(int retries) {
                _retries = retries;
        }

    public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
        if (executionCount >= _retries) {
            // Do not retry if over max retry count
            return false;
        }
        if (exception instanceof NoHttpResponseException) {
            // Retry if the server dropped connection on us
            return true;
        }
        if (exception instanceof SSLHandshakeException) {
            // Do not retry on SSL handshake exception
            return false;
        }
        HttpRequest request = (HttpRequest) context.getAttribute(
                ExecutionContext.HTTP_REQUEST);
        boolean idempotent = !(request instanceof HttpEntityEnclosingRequest); 
        if (idempotent) {
            // Retry if the request is considered idempotent 
            return true;
        }
        return false;
    }

}
 HTTP/1.1 明确地定义了幂等的方法,描述如下[方法也可以有“幂等”属性在那些(除了错误或过期问题)N的副作用>0的相同请求和独立的请求是相同的]换句话说,应用程序应该保证准备着来处理多个相同方法执行的实现。这是可以达到的,比如,通过提供一个独立的事务ID和其它避免执行相同逻辑操作的方法。
0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics