Hello everyone.

The Mixed Reality Forums here are no longer being used or maintained.

There are a few other places we would like to direct you to for support, both from Microsoft and from the community.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.

If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.

And always feel free to hit us up on Twitter @MxdRealityDev.

Transfer file to hololens via POST httprequest (error 429)

Thomas_CThomas_C
edited September 2017 in Questions And Answers

Hello,

I work on a desktop application to communicate with hololens glasses via httprequest (hololens is connected via USB), especially, I want to read and write files. To do that, I use the following code (code is more readable on stackoverflow) :

    // Consts
    public static readonly string API_FileQuery = 
               @"http://{0}/api/filesystem/apps/file";

    public async static void UploadFile(ConnectInfo connectInfo, 
                string knownfolderid, 
                string packagefullname, 
                string path, 
                string filePath)
    {
        try
        {
            // Query
            string query = string.Format(API_FileQuery, 
                                       connectInfo.IP);
            query += "?knownfolderid=" + 
                        Uri.EscapeUriString(knownfolderid);
            query += "&packagefullname=" + 
                        Uri.EscapeUriString(packagefullname);
            query += "&path=" + 
                        Uri.EscapeUriString(path);

            //  Create http request
            var httpRequest = new HttpClient();

            httpRequest.DefaultRequestHeaders.Clear();
            httpRequest.DefaultRequestHeaders.Authorization = 
               new System.Net.Http.Headers.AuthenticationHeaderValue(
            "Basic", EncodeTo64(connectInfo.User + ":" + connectInfo.Password));
            byte[] data = File.ReadAllBytes(filePath);
            ByteArrayContent byteContent = 
                    new ByteArrayContent(data);

            HttpResponseMessage resp = 
                    await httpRequest.PostAsync(query, byteContent);

            var responseMessage = 
                    await resp.Content.ReadAsStringAsync();
        }
        catch (Exception ex)
        {
            //log some problems
        }
    }

    // Helpers
    private static string EncodeTo64(string toEncode)
    {
        byte[] toEncodeAsBytes = Encoding.ASCII.GetBytes(toEncode);
        string returnValue = Convert.ToBase64String(toEncodeAsBytes);
        return returnValue;
    }
}

I already have a GetFile method (same REST API but with GET http request) that works fine and gives me the file I want but the UploadFile method gives me the following response : StatusCode : 429, ReasonPhrase : 'Too Many Requests' (I try to upload a json file).

I don't really understand why I have this error, I just send 1 request (or I'm missing something).

For information, REST API definition can be found there.

Thanks

Answers

Sign In or Register to comment.