fixed bad request bug...
This commit is contained in:
parent
c1b6033ab3
commit
91eedeb27b
@ -60,39 +60,45 @@ public class HttpComponent3 extends AbstractHttpClient {
|
||||
this.httpClient = httpClient;
|
||||
}
|
||||
|
||||
private org.apache.commons.httpclient.HttpMethod method2method(
|
||||
HttpMethod method) {
|
||||
if (method == HttpMethod.GET) {
|
||||
return new GetMethod();
|
||||
} else if (method == HttpMethod.HEAD) {
|
||||
return new HeadMethod();
|
||||
} else if (method == HttpMethod.POST) {
|
||||
return new PostMethod();
|
||||
} else if (method == HttpMethod.PUT) {
|
||||
return new PutMethod();
|
||||
} else if (method == HttpMethod.DELETE) {
|
||||
return new DeleteMethod();
|
||||
} else if (method == HttpMethod.OPTIONS) {
|
||||
return new OptionsMethod();
|
||||
} else {
|
||||
return null;
|
||||
private org.apache.commons.httpclient.HttpMethod createHttpMethod(
|
||||
HttpMethod method, java.net.URI url) throws HttpClientException {
|
||||
org.apache.commons.httpclient.HttpMethod httpMethod = null;
|
||||
try {
|
||||
URI uri = new URI(url.toString(), false, Consts.UTF_8.name());
|
||||
if (method == HttpMethod.GET) {
|
||||
httpMethod = new GetMethod();
|
||||
} else if (method == HttpMethod.HEAD) {
|
||||
httpMethod = new HeadMethod();
|
||||
} else if (method == HttpMethod.POST) {
|
||||
httpMethod = new PostMethod();
|
||||
} else if (method == HttpMethod.PUT) {
|
||||
return new PutMethod();
|
||||
} else if (method == HttpMethod.DELETE) {
|
||||
httpMethod = new DeleteMethod();
|
||||
} else if (method == HttpMethod.OPTIONS) {
|
||||
httpMethod = new OptionsMethod();
|
||||
} else if (method == HttpMethod.TRACE) {
|
||||
return new TraceMethod(uri.getEscapedURI());
|
||||
} else {
|
||||
throw new HttpClientException("unknown request method "
|
||||
+ method + "for" + uri);
|
||||
}
|
||||
httpMethod.setURI(uri);
|
||||
} catch (IOException e) {
|
||||
throw new HttpClientException("I/O error on " + method.name()
|
||||
+ " setURI for \"" + url.toString() + "\":"
|
||||
+ e.getMessage(), e);
|
||||
}
|
||||
return httpMethod;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpResponse execute(HttpRequest request) throws HttpClientException {
|
||||
HttpResponse response = null;
|
||||
try {
|
||||
URI uri = new URI(request.getURI().toString(), false,
|
||||
Consts.UTF_8.name());
|
||||
org.apache.commons.httpclient.HttpMethod httpMethod = method2method(request
|
||||
.getMethod());
|
||||
if (request.getMethod() == HttpMethod.TRACE) {
|
||||
httpMethod = new TraceMethod(uri.getEscapedURI());
|
||||
} else {
|
||||
httpMethod.setURI(uri);
|
||||
}
|
||||
boolean useSSL = "https".equals(uri.getScheme());
|
||||
org.apache.commons.httpclient.HttpMethod httpMethod = createHttpMethod(
|
||||
request.getMethod(), request.getURI());
|
||||
boolean useSSL = "https".equals(request.getURI().getScheme());
|
||||
SSLContext sslContext = null;
|
||||
HttpParams params = request.getParams();
|
||||
if (params != null) {
|
||||
@ -127,7 +133,7 @@ public class HttpComponent3 extends AbstractHttpClient {
|
||||
headers = new HttpHeaders();
|
||||
}
|
||||
if (!headers.containsKey(HttpHeaders.HOST)) {
|
||||
headers.set(HttpHeaders.HOST, uri.getHost());
|
||||
headers.set(HttpHeaders.HOST, request.getURI().getHost());
|
||||
}
|
||||
// Add default accept headers
|
||||
if (!headers.containsKey(HttpHeaders.ACCEPT)) {
|
||||
|
||||
@ -3,10 +3,8 @@ package com.foxinmy.weixin4j.http.factory;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
@ -29,6 +27,7 @@ import org.apache.http.entity.InputStreamEntity;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
import com.foxinmy.weixin4j.http.AbstractHttpClient;
|
||||
import com.foxinmy.weixin4j.http.HttpClientException;
|
||||
import com.foxinmy.weixin4j.http.HttpHeaders;
|
||||
import com.foxinmy.weixin4j.http.HttpMethod;
|
||||
import com.foxinmy.weixin4j.http.apache.MultipartEntity;
|
||||
@ -45,16 +44,26 @@ import com.foxinmy.weixin4j.util.StringUtil;
|
||||
* @see
|
||||
*/
|
||||
public abstract class HttpComponent4 extends AbstractHttpClient {
|
||||
protected static final Map<HttpMethod, HttpRequestBase> methodMap;
|
||||
static {
|
||||
methodMap = new HashMap<HttpMethod, HttpRequestBase>();
|
||||
methodMap.put(HttpMethod.GET, new HttpGet());
|
||||
methodMap.put(HttpMethod.HEAD, new HttpHead());
|
||||
methodMap.put(HttpMethod.POST, new HttpPost());
|
||||
methodMap.put(HttpMethod.PUT, new HttpPut());
|
||||
methodMap.put(HttpMethod.DELETE, new HttpDelete());
|
||||
methodMap.put(HttpMethod.OPTIONS, new HttpOptions());
|
||||
methodMap.put(HttpMethod.TRACE, new HttpTrace());
|
||||
protected HttpRequestBase createHttpRequest(HttpMethod method,
|
||||
java.net.URI uri) throws HttpClientException {
|
||||
if (method == HttpMethod.GET) {
|
||||
return new HttpGet(uri);
|
||||
} else if (method == HttpMethod.HEAD) {
|
||||
return new HttpHead(uri);
|
||||
} else if (method == HttpMethod.POST) {
|
||||
return new HttpPost(uri);
|
||||
} else if (method == HttpMethod.PUT) {
|
||||
return new HttpPut(uri);
|
||||
} else if (method == HttpMethod.DELETE) {
|
||||
return new HttpDelete(uri);
|
||||
} else if (method == HttpMethod.OPTIONS) {
|
||||
return new HttpOptions(uri);
|
||||
} else if (method == HttpMethod.TRACE) {
|
||||
return new HttpTrace(uri);
|
||||
} else {
|
||||
throw new HttpClientException("unknown request method " + method
|
||||
+ "for" + uri);
|
||||
}
|
||||
}
|
||||
|
||||
protected void addHeaders(HttpHeaders headers, HttpRequestBase uriRequest) {
|
||||
|
||||
@ -43,8 +43,8 @@ public class HttpComponent4_1 extends HttpComponent4 {
|
||||
public HttpResponse execute(HttpRequest request) throws HttpClientException {
|
||||
HttpResponse response = null;
|
||||
try {
|
||||
HttpRequestBase uriRequest = methodMap.get(request.getMethod());
|
||||
uriRequest.setURI(request.getURI());
|
||||
HttpRequestBase uriRequest = createHttpRequest(request.getMethod(),
|
||||
request.getURI());
|
||||
boolean useSSL = "https".equals(request.getURI().getScheme());
|
||||
SSLContext sslContext = null;
|
||||
X509HostnameVerifier hostnameVerifier = null;
|
||||
|
||||
@ -41,8 +41,8 @@ public class HttpComponent4_2 extends HttpComponent4 {
|
||||
public HttpResponse execute(HttpRequest request) throws HttpClientException {
|
||||
HttpResponse response = null;
|
||||
try {
|
||||
HttpRequestBase uriRequest = methodMap.get(request.getMethod());
|
||||
uriRequest.setURI(request.getURI());
|
||||
HttpRequestBase uriRequest = createHttpRequest(request.getMethod(),
|
||||
request.getURI());
|
||||
boolean useSSL = "https".equals(request.getURI().getScheme());
|
||||
SSLContext sslContext = null;
|
||||
X509HostnameVerifier hostnameVerifier = null;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user