Skip to content

Commit

Permalink
update test code and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
wyouflf committed Jul 27, 2013
1 parent 717da38 commit fda6b4b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ HttpUtils http = new HttpUtils();
http.send(HttpRequest.HttpMethod.POST,
"updloadurl....",
params,
new RequestCallBack<File>() {
new RequestCallBack<String>() {

@Override
public void onStart() {
Expand All @@ -116,7 +116,7 @@ http.send(HttpRequest.HttpMethod.POST,
}

@Override
public void onSuccess(File result) {
public void onSuccess(String result) {
testTextView.setText("downloaded:" + result.getPath());
}

Expand Down
10 changes: 8 additions & 2 deletions src/com/lidroid/xutils/http/RetryHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package com.lidroid.xutils.http;

import android.os.SystemClock;
import com.lidroid.xutils.util.LogUtils;
import org.apache.http.NoHttpResponseException;
import org.apache.http.client.HttpRequestRetryHandler;
import org.apache.http.client.methods.HttpRequestBase;
Expand Down Expand Up @@ -72,8 +73,13 @@ public boolean retryRequest(IOException exception, int executionCount, HttpConte
}

if (retry) {
HttpRequestBase currentReq = (HttpRequestBase) context.getAttribute(ExecutionContext.HTTP_REQUEST);
retry = currentReq != null && !"POST".equals(currentReq.getMethod());
try {
HttpRequestBase currentReq = (HttpRequestBase) context.getAttribute(ExecutionContext.HTTP_REQUEST);
retry = currentReq != null && !"POST".equals(currentReq.getMethod());
} catch (Exception e) {
retry = false;
LogUtils.e("retry error", e);
}
}

if (retry) {
Expand Down
19 changes: 10 additions & 9 deletions test/src/com/example/test/MyActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public void testButtonClick(View v) {

BitmapUtils.create(this).display(testImageView, "http://bbs.lidroid.com/static/image/common/logo.png");

testDownload();
// testDownload();
testUpload();
}

private void testDownload() {
Expand Down Expand Up @@ -83,16 +84,16 @@ public void onFailure(Throwable error, String msg) {

private void testUpload() {
RequestParams params = new RequestParams();
params.addHeader("name", "value");
params.addQueryStringParameter("name", "value");
params.addBodyParameter("name", "value");
params.addBodyParameter("file", new File("path"));
params.addQueryStringParameter("method", "upload");
params.addQueryStringParameter("path", "/apps/测试应用/test.zip");
params.addQueryStringParameter("access_token", "3.1042851f652496c9362b1cd77d4f849b.2592000.1377530363.3590808424-248414");
params.addBodyParameter("file", new File("/sdcard/test.zip"));

HttpUtils http = new HttpUtils();
http.send(HttpRequest.HttpMethod.POST,
"updloadurl....",
"https://pcs.baidu.com/rest/2.0/pcs/file",
params,
new RequestCallBack<File>() {
new RequestCallBack<String>() {

@Override
public void onStart() {
Expand All @@ -105,8 +106,8 @@ public void onLoading(long total, long current) {
}

@Override
public void onSuccess(File result) {
testTextView.setText("downloaded:" + result.getPath());
public void onSuccess(String result) {
testTextView.setText("uploaded:" + result);
}


Expand Down

0 comments on commit fda6b4b

Please sign in to comment.