in tablestore/src/main/java/com/alicloud/openservices/tablestore/core/utils/HttpRequest.java [152:201]
public HttpURLConnection getHttpConnection() throws IOException {
Map<String, String> mappedHeaders = this.headers;
String strUrl = url;
if (null == strUrl) {
throw new IllegalArgumentException("URL is null for HttpRequest.");
}
if (null == this.method) {
throw new IllegalArgumentException("Method is not set for HttpRequest.");
}
URL url = null;
String[] urlArray = null;
if (MethodType.POST.equals(this.method) && null == getHttpContent()) {
urlArray = strUrl.split("\\?");
url = new URL(urlArray[0]);
} else {
url = new URL(strUrl);
}
System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
HttpURLConnection httpConn = (HttpURLConnection)url.openConnection();
httpConn.setRequestMethod(this.method.toString());
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
httpConn.setUseCaches(false);
if (this.getConnectTimeout() != null) {
httpConn.setConnectTimeout(this.getConnectTimeout());
}
if (this.getReadTimeout() != null) {
httpConn.setReadTimeout(this.getReadTimeout());
}
for (Entry<String, String> entry : mappedHeaders.entrySet()) {
httpConn.setRequestProperty(entry.getKey(), entry.getValue());
}
if (null != getHeaderValue(CONTENT_TYPE)) {
httpConn.setRequestProperty(CONTENT_TYPE, getHeaderValue(CONTENT_TYPE));
} else {
String contentTypeValue = getContentTypeValue(httpContentType, encoding);
if (null != contentTypeValue) {
httpConn.setRequestProperty(CONTENT_TYPE, contentTypeValue);
}
}
if (MethodType.POST.equals(this.method) && null != urlArray && urlArray.length == 2) {
httpConn.getOutputStream().write(urlArray[1].getBytes());
}
return httpConn;
}