|
@@ -11,6 +11,7 @@ import java.io.InputStream;
|
|
import java.io.OutputStream;
|
|
import java.io.OutputStream;
|
|
import java.net.HttpURLConnection;
|
|
import java.net.HttpURLConnection;
|
|
import java.net.MalformedURLException;
|
|
import java.net.MalformedURLException;
|
|
|
|
+import java.net.ProtocolException;
|
|
import java.net.URL;
|
|
import java.net.URL;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
@@ -22,6 +23,7 @@ class LuaHTTPS {
|
|
static private String TAG = "LuaHTTPS";
|
|
static private String TAG = "LuaHTTPS";
|
|
|
|
|
|
private String urlString;
|
|
private String urlString;
|
|
|
|
+ private String method;
|
|
private byte[] postData;
|
|
private byte[] postData;
|
|
private byte[] response;
|
|
private byte[] response;
|
|
private int responseCode;
|
|
private int responseCode;
|
|
@@ -34,6 +36,7 @@ class LuaHTTPS {
|
|
|
|
|
|
public void reset() {
|
|
public void reset() {
|
|
urlString = null;
|
|
urlString = null;
|
|
|
|
+ method = "GET";
|
|
postData = null;
|
|
postData = null;
|
|
response = null;
|
|
response = null;
|
|
responseCode = 0;
|
|
responseCode = 0;
|
|
@@ -50,6 +53,11 @@ class LuaHTTPS {
|
|
this.postData = postData;
|
|
this.postData = postData;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Keep
|
|
|
|
+ public void setMethod(String method) {
|
|
|
|
+ this.method = method.toUpperCase();
|
|
|
|
+ }
|
|
|
|
+
|
|
@Keep
|
|
@Keep
|
|
public void addHeader(String key, String value) {
|
|
public void addHeader(String key, String value) {
|
|
headers.put(key, value);
|
|
headers.put(key, value);
|
|
@@ -110,13 +118,21 @@ class LuaHTTPS {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // Set request method
|
|
|
|
+ try {
|
|
|
|
+ connection.setRequestMethod(method);
|
|
|
|
+ } catch (ProtocolException e) {
|
|
|
|
+ Log.e(TAG, "Error", e);
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
// Set header
|
|
// Set header
|
|
for (Map.Entry<String, String> headerData: headers.entrySet()) {
|
|
for (Map.Entry<String, String> headerData: headers.entrySet()) {
|
|
connection.setRequestProperty(headerData.getKey(), headerData.getValue());
|
|
connection.setRequestProperty(headerData.getKey(), headerData.getValue());
|
|
}
|
|
}
|
|
|
|
|
|
// Set post data
|
|
// Set post data
|
|
- if (postData != null) {
|
|
|
|
|
|
+ if (postData != null && canSendData()) {
|
|
connection.setDoOutput(true);
|
|
connection.setDoOutput(true);
|
|
connection.setChunkedStreamingMode(0);
|
|
connection.setChunkedStreamingMode(0);
|
|
|
|
|
|
@@ -168,4 +184,8 @@ class LuaHTTPS {
|
|
connection.disconnect();
|
|
connection.disconnect();
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private boolean canSendData() {
|
|
|
|
+ return !method.equals("GET") && !method.equals("HEAD");
|
|
|
|
+ }
|
|
}
|
|
}
|