コード例 #1
0
        public void UploadEndpointTest()
        {
            //
            RestClient   client  = new RestClient("https://content.dropboxapi.com/2/");
            IRestRequest request = new RestRequest("files/upload", Method.POST);

            //FileInfo fileInfo = new FileInfo(filePath);
            //long fileLength = fileInfo.Length;

            request.AddHeader("Authorization", "Bearer " + token);

            FileClass fileInfo = new FileClass()
            {
                path            = "/webAPITestingTRPZ2021/HelloWorld.txt",
                mode            = "add",
                autorename      = true,
                mute            = false,
                strict_conflict = false
            };

            string stringjson = JsonConvert.SerializeObject(fileInfo);

            //Console.WriteLine(stringjson);
            request.AddHeader("Dropbox-API-Arg", stringjson);
            request.AddHeader("Content-Type", "application/octet-stream");
            request.AddJsonBody("{}");

            IRestResponse response = client.Execute(request);

            //

            // act
            //IRestResponse response = client.Execute(request);

            // assert
            Console.WriteLine("CODE: ", response.StatusCode);
            Console.WriteLine("Content: ", response.Content);
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
        }