Code: Select all
/*
url = www.google.com;
proxy = "192.168.43.1";
port = "8080";
username_password = "username:password";
requestMethod = "GET"; //GET, POST, PUT, DELETE etc
requestProperty = newMapFromValues(); //add http headers in key value format
body = json body you want to send
param=newList(httpRequest, url, proxy, port, username_password, requestMethod, requestProperty, body)
eval(param[0]);
*/
httpRequest='url=callJavaConstructor("java.net.URL", "URL(java.lang.String)", param[1]);\nif (param[2]!=null and param[3]!=null) {\n\tproxy = callJavaConstructor("java.net.Proxy", "Proxy(java.net.Proxy$Type, java.net.SocketAddress)", getJavaStaticField("java.net.Proxy$Type", "HTTP"), callJavaConstructor("java.net.InetSocketAddress", "InetSocketAddress(java.lang.String, int)", param[2], param[3]));\n\tconnection=callJavaMethod(url, "java.net.URL", "openConnection(java.net.Proxy)", proxy);\n} else {\n\tconnection=callJavaMethod(url, "java.net.URL", "openConnection()");\n}\nif (param[4]!=null) {\n\tbasicAuth = "Basic " + callJavaStaticMethod("android.util.Base64", "encodeToString(byte[], int)", callJavaMethod(param[4], "java.lang.String", "getBytes()"), getJavaStaticField("android.util.Base64", "NO_WRAP"));\n\tcallJavaMethod(connection, "java.net.URLConnection", "setRequestProperty(java.lang.String, java.lang.String)", "Authorization", basicAuth) \n}\ncallJavaMethod(connection, "java.net.HttpURLConnection", "setRequestMethod(java.lang.String)", param[5]);\nif (isMap(param[6])) {\n\tfor (key in getMapKeys(param[6])) {\n\t\tcallJavaMethod(connection, "java.net.URLConnection", "setRequestProperty(java.lang.String, java.lang.String)", key, param[6][key]);\n\t}\n}\nif (param[7]!=null) {\n\tcallJavaMethod(connection, "java.net.URLConnection", "setDoOutput(boolean)", true);\n\tcallJavaMethod(connection, "java.net.URLConnection", "setRequestProperty(java.lang.String, java.lang.String)", "Content-Length", length("{param[4],jsonformat}"));\n\toutputStream=callJavaMethod(connection, "java.net.URLConnection", "getOutputStream()");\n\tcallJavaMethod(outputStream, "java.io.OutputStream", "write(byte[])", callJavaMethod("{param[4],jsonformat}", "java.lang.String", "getBytes()"));\n\tcallJavaMethod(outputStream, "java.io.OutputStream", "close()");\n}\ncallJavaMethod(connection, "java.net.URLConnection", "connect()");\nresponseCode=callJavaMethod(connection, "java.net.HttpURLConnection", "getResponseCode()");\nheaders=callJavaMethod(connection, "java.net.URLConnection", "getHeaderFields()");\n\nerrorstream=callJavaMethod(connection, "java.net.HttpURLConnection", "getErrorStream()");\nif (errorstream!=null) {\n\treader=callJavaConstructor("java.io.BufferedReader", "BufferedReader(java.io.Reader)", callJavaConstructor("java.io.InputStreamReader", "InputStreamReader(java.io.InputStream)", errorstream));\n\tresponse=callJavaConstructor("java.lang.StringBuffer", "StringBuffer()");\n\tline="";\n\twhile ((line=callJavaMethod(reader, "java.io.BufferedReader", "readLine()"))!=null) {\n\t\tcallJavaMethod(response, "java.lang.StringBuffer", "append(java.lang.CharSequence)", line+"\\n")\n\t}\n} else {\n\tstream=callJavaMethod(connection, "java.net.URLConnection", "getInputStream()");\n\treader=callJavaConstructor("java.io.BufferedReader", "BufferedReader(java.io.Reader)", callJavaConstructor("java.io.InputStreamReader", "InputStreamReader(java.io.InputStream)", stream));\n\tresponse=callJavaConstructor("java.lang.StringBuffer", "StringBuffer()");\n\tline="";\n\twhile ((line=callJavaMethod(reader, "java.io.BufferedReader", "readLine()"))!=null) {\n\t\tcallJavaMethod(response, "java.lang.StringBuffer", "append(java.lang.CharSequence)", line+"\\n")\n\t}\n}'
Create a script. Paste above code.
Then
Code: Select all
param = newList(httpRequest, "http://www.facebook.com", "168.235.95.186", "41360", "ceJuGc:pdxksg", "GET", null, null);
eval(param[0])
Limitation of above method is that your other script/expression won't run until above code finishes. So if you are doing for large size file then it's not a good way.