feat: 优化API 修复http模块错误

This commit is contained in:
coding
2018-01-09 12:19:02 +00:00
parent a6be26206e
commit 96f93754e6
3 changed files with 30 additions and 35 deletions

View File

@ -47,7 +47,7 @@ function open(url, method, header) {
var conn = new URL(url).openConnection();
if (conn instanceof HttpsURLConnection) {
conn.setHostnameVerifier(TrustAnyHostnameVerifier);
conn.setSSLSocketFactory(TrustAnyHostnameVerifier);
conn.setSSLSocketFactory(SSLSocketFactory);
}
conn.setRequestMethod(method);
conn.setDoOutput(true);
@ -81,10 +81,12 @@ function request(url, method, header, params, body) {
var conn = open(buildUrl(url, params), method, header);
try {
conn.connect();
var out = conn.getOutputStream();
out.write(new String(body).getBytes(config.Charset));
out.flush();
out.close();
if (body) {
var out = conn.getOutputStream();
out.write(new String(body).getBytes(config.Charset));
out.flush();
out.close();
}
return response(conn);
} finally {
conn.disconnect();
@ -110,4 +112,4 @@ var http = {
}
})
exports = module.exports = http;
exports = module.exports = http;