I am trying to call an Azure Function with HTTP Trigger from Android App using Volley. I have verified that this Function responds using Postman Chrome extension.
Here is the basic Azure functions:
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
log.Info($"C# HTTP trigger function processed a request. RequestUri={req.RequestUri}");
string jsonContent = await req.Content.ReadAsStringAsync();
dynamic data = JsonConvert.DeserializeObject(jsonContent);
log.Info($"Subject: {data.subject}");
log.Info($"Subject: {data.name}");
return req.CreateResponse(HttpStatusCode.OK, $"All went well.");
}
I just want to log the parameters. And here is the Java code calling from Android
Gson gson = new Gson();
String jsonString = gson.toJson(mailObject);
try {
JsonObjectRequest jsObjRequest = new JsonObjectRequest
(Request.Method.POST, Constants.AZURE_FUNCTION_URL, new JSONObject(jsonString), new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
mView.showMessage("Response: " + response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// TODO Auto-generated method stub
mView.showMessage(error.getMessage());
Log.d(LOG_TAG, "Error1: " + error.getMessage());
}
});
// Access the RequestQueue through your singleton class.
VolleySingleton.getInstance(mContext).addToRequestQueue(jsObjRequest);
} catch (JSONException e) {
e.printStackTrace();
}
And here is the simple data object that I serialized and passed to the call.
public class MailObject {
@SerializedName("name")
public String sendFromName;
@SerializedName("subject")
public String subject;
}
I am getting the following Network error, any pointer on what I can do differently will be appreciated.
E/Volley: [1637] BasicNetwork.performRequest: Unexpected response code 404 for https://myfunction.azurewebsites.net/api/functioname?code=xxxxxxxxxxxxxx