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