1

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
Val Okafor
  • 3,371
  • 13
  • 47
  • 72
  • please make sure that you use the correct Azure Function URL. I use the default Function URL and I could access by using your code. you could try to access this URL https://johnny-functionapp.azurewebsites.net/api/HttpTriggerCSharp1?code=9bzzgxh4c1moz03vehmxp41alfqxivmxfrpy – johnny Oct 14 '16 at 10:22
  • Perhaps CORS is preventing you? – 4c74356b41 Oct 14 '16 at 17:09
  • I have posted the answer here. http://stackoverflow.com/questions/40100807/pass-parameter-with-volley-post – Naren Oct 18 '16 at 22:06
  • Thanks, that was helpful – Val Okafor Oct 19 '16 at 03:38

0 Answers0