I know that a similar question has been asked several times, but I can not find a solution for a simple problem: PATCHverb.
Therefore, I ask anyone who has solved the PATCH problem in Android either using OkHttp, Volley or Retrofit (or if you used another method or library, please share).
I spent 3 days searching, and I can not find a solution to this problem. All I am trying to do is to partially update the table through the RESTful API, which is built and running in the .NET environment.
I am currently using Volley, but every time I run the application, I get an exception error that says something along the lines PATCH is not an allowed...?, and then gives an array of other verbs that can be used, such as "POST", PUT, GET. .. ". So, not very useful at all.
I tried using OkHttpas follows:
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("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 it requestcannot be applied to Request.Builder.
I'm new to OkHttp, by the way.
In any case, I try my best to PATCHwork too long. Maybe I'm shooting in the dark, but if anyone has suggestions, thoughts on how to make PATCH work, I will be forever grateful to you.
Thank you for your help.