XHttp.getInstance().initTask().get("http://3434343434")
.setTag("aaa")
.setOnTaskCallback(new OnTaskCallback() {
@Override
public void onSuccess(Response response) {
Log.i("xxx", "response " +response.toString());
mTextView.setText(response.toString());
}
@Override
public void onFailure(Exception ex, String errorCode) {
Log.i("xxx", "onFailure " +ex.toString());
Log.i("xxx", "onFailure " +errorCode);
}
});
XHttp.getInstance().initTask().get("http://sdadadadasd")
.setTag("bbb")
.setTimeout(5000)
.setOnTaskCallback(new OnTaskCallback() {
@Override
public void onSuccess(final Response response) {
mImageView.setImageBitmap(response.toBitmap());
Log.i("xxx", "onSuccess" );
}
@Override
public void onFailure(Exception ex, String errorCode) {
Log.i("xxx", "onFailure " +ex.toString());
Log.i("xxx", "onFailure " +errorCode);
}
});
String basePtah = Environment.getExternalStorageDirectory().getPath();
String[] path = new String[]{basePtah+ "/setting.cfg",basePtah+"/Screenshot.png"};
XHttp.getInstance()
.initTask()
.post(WebApi.UPLOAD_FILE_URL)//url
.setHeads("platform","mobile_phone")//设置请求头
.uploadFiles(path)//文件路径(完整路径)
.setOnTaskCallback(new OnTaskCallback() {
@Override
public void onSuccess(final Response response) {
JJLogger.logInfo(TAG,"MainActivity.onSuccess :"+
response.toString());
Toast.makeText(MainActivity.this, response.toString(), Toast.LENGTH_LONG).show();
}
@Override
public void onFailure(final Exception ex, final String errorCode) {
JJLogger.logInfo(TAG,"MainActivity.onFailure :"+ex.getMessage());
}
});
String basePtah = Environment.getExternalStorageDirectory().getPath();
String path = basePtah+ "/setting.cfg";
XHttp.getInstance()
.initTask()
.post(WebApi.UPLOAD_FILE_URL)//url
.setHeads("platform","mobile_phone")//设置请求头
.uploadFile(path)//文件路径(完整路径)
.setOnTaskCallback(new OnTaskCallback() {
@Override
public void onSuccess(final Response response) {
JJLogger.logInfo(TAG,"MainActivity.onSuccess :"+
response.toString());
Toast.makeText(MainActivity.this, response.toString(), Toast.LENGTH_LONG).show();
}
@Override
public void onFailure(final Exception ex, final String errorCode) {
JJLogger.logInfo(TAG,"MainActivity.onFailure :"+ex.getMessage());
}
});
final StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < 20; i++) {
final int finalI = i;
XHttp.getInstance().initTask().post(WebApi.LOGIN_URL)
.setParams("account", mName.getText().toString())
.setParams("password", mAge.getText().toString())
.startConcurrenceThreadPool()
.setOnTaskCallback(new OnTaskCallback() {
@Override
public void onSuccess(final Response response) {
Log.i("task","MainActivity.onSuccess 任务"+ finalI +"完成:");
stringBuilder.append("并行 任务"+ finalI +"完成:").append("\n");
mTextView1.setText(stringBuilder.toString());
}
@Override
public void onFailure(final Exception ex, final String errorCode) {
JJLogger.logInfo(TAG, "MainActivity.onFailure :" + ex.getMessage());
}
});
}
final StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < 20; i++) {
final int finalI = i;
XHttp.getInstance().initTask().post(WebApi.LOGIN_URL)
.setParams("account", mName.getText().toString())
.setParams("password", mAge.getText().toString())
.startSerialThreadPool()
.setOnTaskCallback(new OnTaskCallback() {
@Override
public void onSuccess(final Response response) {
Log.i("task","MainActivity.onSuccess 任务"+ finalI +"完成:");
stringBuilder.append("串行 任务"+ finalI +"完成:").append("\n");
mTextView2.setText(stringBuilder.toString());
}
@Override
public void onFailure(final Exception ex, final String errorCode) {
JJLogger.logInfo(TAG, "MainActivity.onFailure :" + ex.getMessage());
}
});
}