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和其它避免执行相同逻辑操作的方法。
HTTP提交表单数据及重试处理技术
本文深入探讨了使用HTTP提交表单数据时的编码方式,并提供了处理无key情况的请求方法。同时,介绍了如何在POST请求中实现自定义异常恢复机制,包括请求重试处理和幂等性的考量。
156

被折叠的 条评论
为什么被折叠?



