mirror of
https://github.com/silkimen/cordova-plugin-advanced-http.git
synced 2026-07-26 00:00:14 +08:00
Started refactoring things so they make more sense name wise
This commit is contained in:
+1
-1
@@ -34,7 +34,7 @@ import android.content.res.AssetManager;
|
||||
import android.util.Base64;
|
||||
import android.util.Log;
|
||||
|
||||
public class CordovaHTTP extends CordovaPlugin {
|
||||
public class CordovaHttpPlugin extends CordovaPlugin {
|
||||
private static final String TAG = "CordovaHTTP";
|
||||
|
||||
private SSLContext sslContext;
|
||||
@@ -13,8 +13,11 @@ import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.BufferedReader;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
|
||||
@@ -67,18 +70,22 @@ public class HTTP {
|
||||
this.headers = headers;
|
||||
}
|
||||
|
||||
protected SSLContext getSSLContext() {
|
||||
return this.sslContext;
|
||||
}
|
||||
|
||||
protected HostnameVerifier getHostnameVerifier() {
|
||||
return this.hostnameVerifier;
|
||||
}
|
||||
|
||||
protected CallbackContext getCallbackContext() {
|
||||
return this.callbackContext;
|
||||
}
|
||||
|
||||
protected HttpsURLConnection openConnection(String urlString) throws MalformedURLException, IOException {
|
||||
URL url = new URL(urlString);
|
||||
HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();
|
||||
if (this.hostnameVerifier != null) {
|
||||
conn.setHostnameVerifier(this.hostnameVerifier);
|
||||
}
|
||||
if (this.sslContext != null) {
|
||||
conn.setSSLSocketFactory(this.sslContext.getSocketFactory());
|
||||
}
|
||||
return conn;
|
||||
}
|
||||
|
||||
protected void addHeaders(URLConnection conn) throws JSONException {
|
||||
Iterator<?> i = this.headers.keys();
|
||||
|
||||
|
||||
@@ -35,8 +35,7 @@ public class HTTPGet extends HTTP implements Runnable {
|
||||
if (params.length() > 0) {
|
||||
urlString = urlString + "?" + this.getQueryString();
|
||||
}
|
||||
URL url = new URL(urlString);
|
||||
conn = (HttpsURLConnection)url.openConnection();
|
||||
conn = this.openConnection(urlString);
|
||||
conn.setRequestMethod("GET");
|
||||
conn.setDoInput(true);
|
||||
conn.setRequestProperty("Accept-Charset", charset);
|
||||
|
||||
@@ -34,16 +34,7 @@ public class HTTPPost extends HTTP implements Runnable {
|
||||
InputStream is = null;
|
||||
HttpsURLConnection conn = null;
|
||||
try {
|
||||
URL url = new URL(urlString);
|
||||
conn = (HttpsURLConnection)url.openConnection();
|
||||
HostnameVerifier hostnameVerifier = this.getHostnameVerifier();
|
||||
if (hostnameVerifier != null) {
|
||||
conn.setHostnameVerifier(hostnameVerifier);
|
||||
}
|
||||
SSLContext context = this.getSSLContext();
|
||||
if (context != null) {
|
||||
conn.setSSLSocketFactory(this.getSSLContext().getSocketFactory());
|
||||
}
|
||||
conn = this.openConnection(urlString);
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setDoInput(true);
|
||||
conn.setDoOutput(true);
|
||||
|
||||
Reference in New Issue
Block a user