Skip to content

Commit 3d31db1

Browse files
committed
PUT request with sample
1 parent 2122a13 commit 3d31db1

File tree

4 files changed

+67
-1
lines changed

4 files changed

+67
-1
lines changed

library/src/main/java/com/loopj/android/http/RequestFactory.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.loopj.android.http.requests.GetRequest;
2121
import com.loopj.android.http.requests.PatchRequest;
2222
import com.loopj.android.http.requests.PostRequest;
23+
import com.loopj.android.http.requests.PutRequest;
2324

2425
import cz.msebera.android.httpclient.Header;
2526
import cz.msebera.android.httpclient.HttpEntity;
@@ -41,4 +42,8 @@ public static RequestInterface delete(String URL, Header[] headers) {
4142
public static RequestInterface patch(String URL, Header[] headers, HttpEntity patchEntity) {
4243
return new PatchRequest(false, URL, headers, patchEntity, null);
4344
}
45+
46+
public static RequestInterface put(String URL, Header[] headers, HttpEntity putEntity) {
47+
return new PutRequest(false, URL, headers, putEntity, null);
48+
}
4449
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.loopj.android.http.requests;
2+
3+
import cz.msebera.android.httpclient.Header;
4+
import cz.msebera.android.httpclient.HttpEntity;
5+
import cz.msebera.android.httpclient.client.methods.HttpPut;
6+
import cz.msebera.android.httpclient.client.methods.HttpUriRequest;
7+
8+
public class PutRequest extends BaseRequestWithEntity {
9+
public PutRequest(boolean synchronous, String url, Header[] headers, HttpEntity entity, Object TAG) {
10+
super(synchronous, url, headers, entity, TAG);
11+
}
12+
13+
@Override
14+
public HttpUriRequest build() {
15+
HttpPut put = new HttpPut(getURL());
16+
put.setEntity(getEntity());
17+
return put;
18+
}
19+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 PutSample extends SampleParentActivity {
12+
@Override
13+
public ResponseHandlerInterface getResponseHandler() {
14+
return defaultResponseHandler;
15+
}
16+
17+
@Override
18+
public String getDefaultURL() {
19+
return "https://httpbin.org/put";
20+
}
21+
22+
@Override
23+
public boolean isRequestHeadersAllowed() {
24+
return true;
25+
}
26+
27+
@Override
28+
public boolean isRequestBodyAllowed() {
29+
return true;
30+
}
31+
32+
@Override
33+
public int getSampleTitle() {
34+
return R.string.title_put_sample;
35+
}
36+
37+
@Override
38+
public RequestHandle executeSample(AsyncHttpClient client, String URL, Header[] headers, HttpEntity entity, ResponseHandlerInterface responseHandler) {
39+
return client.sendRequest(RequestFactory.put(URL, headers, entity), responseHandler);
40+
}
41+
}

sample/src/main/java/com/loopj/android/http/sample/WaypointsActivity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ public class WaypointsActivity extends ListActivity {
3434
new SampleConfig(R.string.title_get_sample, GetSample.class),
3535
new SampleConfig(R.string.title_post_sample, PostSample.class),
3636
new SampleConfig(R.string.title_delete_sample, DeleteSample.class),
37-
new SampleConfig(R.string.title_patch_sample, PatchSample.class)
37+
new SampleConfig(R.string.title_patch_sample, PatchSample.class),
38+
new SampleConfig(R.string.title_put_sample, PutSample.class)
3839
};
3940

4041
@Override

0 commit comments

Comments
 (0)