从Android应用程序调用Azure功能

时间:2016-10-14 05:02:44

标签: android azure android-volley azure-functions

我正在尝试使用Volley从Android应用程序调用带有HTTP触发器的Azure功能。我已经确认此功能使用Postman Chrome扩展程序进行响应。

以下是Azure的基本功能:

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.");

}

我只想记录参数。这是从Android调用的Java代码

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();

        }

这是我序列化并传递给调用的简单数据对象。

public class MailObject {

    @SerializedName("name")
    public String sendFromName;

    @SerializedName("subject")
    public String subject;
}

我收到以下网络错误,任何关于我可以采取不同做法的指针都将受到赞赏。

E/Volley: [1637] BasicNetwork.performRequest: Unexpected response code 404 for https://myfunction.azurewebsites.net/api/functioname?code=xxxxxxxxxxxxxx

0 个答案:

没有答案