Search code examples
c#azurewindows-phone-8azure-mobile-services

How to add own header to Azure Mobile Services call?


I've got Azure Mobile Service API and I would like to make call to it from Windows Phone application.

So I use something like that:

public static async Task<bool> InvokeGetUsers()
        {
            Dictionary<string, string> headers = new Dictionary<string, string>();
            headers.Add("X-USER-TOKEN", App.userInfo.token);
            headers.Add("X-ZUMO-APPLICATION", "nxdQEvWOERLaHocwMz");

            Dictionary<string, string> arguments = new Dictionary<string, string>();
            arguments.Add("uuid", "123456");

            if (App.mobileServiceClient != null)
            {
                App.userFriends = await App.mobileServiceClient.InvokeApiAsync<List<GetUsers>>("get_users", System.Net.Http.HttpMethod.Post, arguments);
                return true;
            }
            return false;
        }

What I can't do is to pass header information to my call, how to do that?


Solution

  • There is an overloaded version of the InvokeApiAsync-method that you could use:

    public Task<HttpResponseMessage> InvokeApiAsync(
        string apiName,
        HttpContent content,
        HttpMethod method,
        IDictionary<string, string> requestHeaders,
        IDictionary<string, string> parameters
    )
    

    More information here: https://msdn.microsoft.com/en-us/library/dn268343.aspx