add: http.postMultipart
This commit is contained in:
41
app/src/main/assets/sample/HTTP网络请求/文件上传.js
Normal file
41
app/src/main/assets/sample/HTTP网络请求/文件上传.js
Normal file
@@ -0,0 +1,41 @@
|
||||
//如果遇到SocketTimeout的异常,重新多运行几次脚本即可
|
||||
|
||||
console.show();
|
||||
example1();
|
||||
example2();
|
||||
example3();
|
||||
example4();
|
||||
example5();
|
||||
|
||||
function example1(){
|
||||
var res = http.postMultipart("http://posttestserver.com/post.php", {
|
||||
"file": open("/sdcard/1.txt")
|
||||
});
|
||||
log("例子1:");
|
||||
log(res.body.string());
|
||||
}
|
||||
|
||||
function example2(){
|
||||
var res = http.postMultipart("http://posttestserver.com/post.php", {
|
||||
"file": ["1.txt", "/sdcard/1.txt"]
|
||||
});
|
||||
log("例子2:");
|
||||
log(res.body.string());
|
||||
}
|
||||
|
||||
function example3(){
|
||||
var res = http.postMultipart("http://posttestserver.com/post.php", {
|
||||
"file": ["1.txt", "text/plain", "/sdcard/1.txt"]
|
||||
});
|
||||
log("例子3:");
|
||||
log(res.body.string());
|
||||
}
|
||||
|
||||
function example4(){
|
||||
var res = http.postMultipart("http://posttestserver.com/post.php", {
|
||||
"file": open("/sdcard/1.txt"),
|
||||
"aKey": "aValue"
|
||||
});
|
||||
log("例子4:");
|
||||
log(res.body.string());
|
||||
}
|
||||
@@ -31,8 +31,13 @@ import com.stardust.util.UiHandler;
|
||||
import org.autojs.dynamiclayoutinflater.ImageLoader;
|
||||
import org.autojs.dynamiclayoutinflater.util.Drawables;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.MultipartBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/1/27.
|
||||
*/
|
||||
@@ -71,8 +76,8 @@ public class App extends MultiDexApplication {
|
||||
return;
|
||||
}
|
||||
LeakCanary.install(this);
|
||||
//if (!BuildConfig.DEBUG)
|
||||
Thread.setDefaultUncaughtExceptionHandler(new CrashHandler(ErrorReportActivity.class));
|
||||
if (!BuildConfig.DEBUG)
|
||||
Thread.setDefaultUncaughtExceptionHandler(new CrashHandler(ErrorReportActivity.class));
|
||||
}
|
||||
|
||||
private void init() {
|
||||
|
||||
Reference in New Issue
Block a user