[ Android Patch request ]
1. HttpPost의 Header에 X-HTTP-Method-Override 추가
httpost.setHeader("X-HTTP-Method-Override", "PATCH");
2. 위 1번 방법이 되지 않을 경우 okHttp 활용(Android Studio 기준)
I) build.gradle에 library 추가
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
...
compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'com.squareup.okhttp3:okhttp-urlconnection:3.2.0'
}
II) CustomHttpStack 추가
import com.android.volley.toolbox.HurlStack;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import okhttp3.OkHttpClient;
import okhttp3.OkUrlFactory;
public class CustomHttpStack extends HurlStack {
private final OkUrlFactory mFactory;
public CustomHttpStack() {
this(new OkHttpClient());
}
public CustomHttpStack(OkHttpClient client) {
if (client == null) {
return;
}
mFactory = new OkUrlFactory(client);
}
@Override
protected HttpURLConnection createConnection(URL url) throws IOException {
return mFactory.open(url);
}
}
III) Send Patch Request
Volley.newRequestQueue(context, new CustomHttpStack()).add(request);
'Programming > Android' 카테고리의 다른 글
[Android] Spannable (0) | 2017.01.02 |
---|---|
[Android] GPS 설정 체크하기 (0) | 2016.12.18 |
[Android] Activity Life Cycle(생명주기) (1) | 2015.12.14 |
[Android] 외부 앱 실행 (0) | 2015.11.30 |
[Android] Android Soft KeyBoard Show and Hide (0) | 2015.11.18 |