Skip to content

Commit 341215e

Browse files
authored
add redirect sample (android-async-http#1336)
1 parent e5de9e5 commit 341215e

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

sample/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<activity android:name=".PatchSample" />
3131
<activity android:name=".OptionsSample" />
3232
<activity android:name=".JsonSample" />
33+
<activity android:name=".RedirectSample" />
3334
<activity android:name=".JsonStreamerSample" />
3435
<activity android:name=".FileSample" />
3536
<activity android:name=".DirectorySample" />
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.loopj.android.http.sample;
2+
3+
import com.loopj.android.http.AsyncHttpClient;
4+
import com.loopj.android.http.RequestFactory;
5+
import com.loopj.android.http.interfaces.ResponseHandlerInterface;
6+
import com.loopj.android.http.utils.RequestHandle;
7+
8+
import cz.msebera.android.httpclient.Header;
9+
import cz.msebera.android.httpclient.HttpEntity;
10+
11+
public class RedirectSample extends SampleParentActivity {
12+
13+
@Override
14+
public String getLogTag() {
15+
return "RedirectSample";
16+
}
17+
18+
@Override
19+
public RequestHandle executeSample(AsyncHttpClient client, String URL, Header[] headers, HttpEntity entity, ResponseHandlerInterface responseHandler) {
20+
client.setEnableRedirectStrategy(true);
21+
return client.sendRequest(RequestFactory.get(URL, headers), responseHandler);
22+
}
23+
24+
@Override
25+
public int getSampleTitle() {
26+
return R.string.title_get_sample;
27+
}
28+
29+
@Override
30+
public boolean isRequestBodyAllowed() {
31+
return false;
32+
}
33+
34+
@Override
35+
public boolean isRequestHeadersAllowed() {
36+
return true;
37+
}
38+
39+
@Override
40+
public String getDefaultURL() {
41+
return PROTOCOL+"httpbin.org/status/301";
42+
}
43+
44+
@Override
45+
public ResponseHandlerInterface getResponseHandler() {
46+
return defaultResponseHandler;
47+
}
48+
}

0 commit comments

Comments
 (0)