I know a similar question has been asked a few times now, but I can't seem to find a solution for a simple problem: PATCH
verb.
So I ask anyone who as solved the PATCH issue in Android either by using OkHttp, Volley or Retrofit ( or if you used a different method or library, please share).
I have spent 3 days digging around and I can't find any solutions to this problem. All I am trying to do is to do a partial update to a table via RESTful API which is built and ran in .NET environment.
I am currently using Volley, but every time I run the app, I get the exception error that says something along the lines of PATCH is not an allowed...?
and it then gives a array of other verbs that can be used such as "POST, PUT, GET...". So, not very helpful at all.
I have tried using OkHttp
like this:
JSONObject infoRequestBody = new JSONObject();
try {
infoRequestBody.put("Salutation", "MRrr.");
infoRequestBody.put("FirstName", "Work Now!!");
infoRequestBody.put("LastName", "Test from my mobile again!! Okhttp");
infoRequestBody.put("MiddleName", "From the Mobile");
infoRequestBody.put("NickName", null);
infoRequestBody.put("BirthDate", "1978-11-23T00:00:00.000Z");
infoRequestBody.put("CompanyName", null);
// infoRequestBody.put("RegDate", "2015-01-18T23:39:13.873Z");
infoRequestBody.put("Gender", "Male");
infoRequestBody.put("IsPregnant", null);
infoRequestBody.put("IsNursing", null);
infoRequestBody.put("WorkPhone", null);
infoRequestBody.put("WorkPhoneExt", null);
infoRequestBody.put("PhoneNumber", null);
infoRequestBody.put("Address", "My android app working!!");
infoRequestBody.put("Address2", null);
infoRequestBody.put("City", null);
infoRequestBody.put("State", "CA");
infoRequestBody.put("ZipCode", null);
infoRequestBody.put("EmailAddress", "email@me.com");
infoRequestBody.put("Occupation", null);
infoRequestBody.put("CountryofResidence", "United States");
infoRequestBody.put("CountryCode", "US");
infoRequestBody.put("Ethnicity", "Asian");
infoRequestBody.put("ModifiedDate", "2015-01-18T23:39:13.873Z");
infoRequestBody.put("ModifiedBy", null);
infoRequestBody.put("AcceptedTerms", true);
infoRequestBody.put("AcceptedPrivacyPolicyCheckbox", false);
infoRequestBody.put("AcceptedUnder18ConsentCheckbox", false);
} catch (JSONException e1) {
e1.printStackTrace();
}
RequestBody body = com.squareup.okhttp.RequestBody.create(JSON, infoRequestBody.toString());
com.squareup.okhttp.Request.Builder request = new com.squareup.okhttp.Request.Builder()
.url("APIUrls.PATIENT_INFO_URL")
.addHeader("Content-Type", "application/json")
.addHeader("Accept", "application/json")
.addHeader("X-ZUMO-APPLICATION", APIUrls.ZUMO_KEY)
.patch(body);
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(com.squareup.okhttp.Request request, IOException e) {
}
@Override
public void onResponse(com.squareup.okhttp.Response response) throws IOException {
if (!response.isSuccessful()) throw new IOException("Unexpected code" + response);
Headers responseHeaders = response.headers();
for (int i = 0; i < responseHeaders.size(); i++) {
System.out.println(responseHeaders.name(i) + ": " + responseHeaders.value(i));
}
System.out.println(response.body().string());
}
});
but client.newCall(request).enque(new Callback()...
gives me an error saying that the request
can not be applied to Request.Builder
.
I am new to OkHttp, by the way.
Anyways, I have been struggling to get PATCH
to work for far too long. Maybe I am shooting in the dark, but if anyone out there has any suggestions, thoughts on how to get 'PATCH` to work, I'd be forever grateful to you.
Thanks for your help.