当前位置: 首页>>代码示例>>C#>>正文


C# WebClient.UploadDataTaskAsync方法代码示例

本文整理汇总了C#中System.Net.WebClient.UploadDataTaskAsync方法的典型用法代码示例。如果您正苦于以下问题:C# WebClient.UploadDataTaskAsync方法的具体用法?C# WebClient.UploadDataTaskAsync怎么用?C# WebClient.UploadDataTaskAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.WebClient的用法示例。


在下文中一共展示了WebClient.UploadDataTaskAsync方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Reduce

        public async Task Reduce(FileInfo input, FileInfo output)
        {
            if (input == null)
            {
                throw new ArgumentException("Missing parameter input", "input");
            }

            if (output == null)
            {
                throw new ArgumentException("Missing parameter outputDirectory", "outputDirectory");
            }

            var fileName = input.Name;
            var endpoint = new Uri("https://api.accusoft.com/v1/imageReducers/" + fileName);
            
            using (var client = new WebClient())
            {
                client.Headers.Add("acs-api-key", _apiKey);
                client.Headers.Add("Content-Type", input.Extension == "png" ? "image/png" : "image/jpg");

                using (var reader = new BinaryReader(input.OpenRead()))
                {
                    var data = reader.ReadBytes((int)reader.BaseStream.Length);
                    var result = await client.UploadDataTaskAsync(endpoint, "POST", data);

                    using (var writeStream = output.Create())
                    {
                        await writeStream.WriteAsync(result, 0, result.Length);
                    }
                }
            }
        }
开发者ID:kennedykinyanjui,项目名称:csharp-image-compression-example-code-ACS,代码行数:32,代码来源:CompressService.cs

示例2: GetHttpResponseAsync

 public static async Task<string> GetHttpResponseAsync(string url, string data)
 {
     var client = new WebClient();
     client.Headers.Add("user-agent", "User-Agent: Mozilla/5.0");
     client.Headers.Add("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
     byte[] rawData = await client.UploadDataTaskAsync(url, Encoding.UTF8.GetBytes(data));
     return Encoding.UTF8.GetString(rawData);
 }
开发者ID:codic-project,项目名称:codic-vs-extension,代码行数:8,代码来源:Utils.cs

示例3: UploadAsync

 public async Task UploadAsync(string url, IDictionary<string, string> headers, string method, byte[] data)
 {
     var client = new WebClient();
     if (headers != null)
     {
         foreach (var header in headers)
             client.Headers[header.Key] = header.Value;
     }
     await client.UploadDataTaskAsync(url, "PUT", data);
 }
开发者ID:neilunadkat,项目名称:appacitive-dotnet-sdk,代码行数:10,代码来源:WebClientHttpFileHandler.cs

示例4: UploadAsync

 public async Task UploadAsync(string url, IDictionary<string, string> headers, string method, byte[] data)
 {
     using (var client = new WebClient())
     {
         SubscribeToUploadEvents(client);
         if (headers != null)
         {
             foreach (var header in headers)
                 client.Headers[header.Key] = header.Value;
         }
         await client.UploadDataTaskAsync(url, "PUT", data);
         UnsubscribeFromUploadEvents(client);
     }
 }
开发者ID:ytokas,项目名称:appacitive-dotnet-sdk,代码行数:14,代码来源:WebClientHttpFileHandler.cs

示例5: ConvertToTextAsync

        public async Task<SpeechToTextResult> ConvertToTextAsync(byte[] voice)
        {
            var wc = new WebClient();
            //wc.Headers["Content-Type"] = "audio/x-flac; rate=16000";
            wc.Headers["Content-Type"] = "audio/x-flac; rate=8000";

            //var contents = File.ReadAllBytes("i_like_pickles.flac");
            var url = "https://www.google.com/speech-api/v1/recognize?xjerr=1&client=chromium&lang=en-US";
            var result = await wc.UploadDataTaskAsync(url, voice);
            var txt = Encoding.UTF8.GetString(result);
            var obj = JsonConvert.DeserializeObject<SpeechToTextResult>(txt);
            obj.Raw = txt;
            return obj;
            //return resultObj.Hypotheses["utterance"];
            //return resultObj.Hypotheses.First().Utterance;
        }
开发者ID:dinandjait,项目名称:tim5,代码行数:16,代码来源:GoogleSpeechToText.cs

示例6: GetAlertsFromRRS

        private Task<AnomalyRecord[]> GetAlertsFromRRS(string timeSeriesData)
        {
            var rrs = _detectorUrl;
            var apikey = _detectorAuthKey;

            using (var wb = new WebClient())
            {
                wb.Headers[HttpRequestHeader.ContentType] = "application/json";
                wb.Headers.Add(HttpRequestHeader.Authorization, "Bearer " + apikey);

                var featureVector = string.Format("\"data\": \"{0}\",\"params\": \"{1}\"", timeSeriesData, _spikeDetectorParams);
                string jsonData = "{\"Id\":\"scoring0001\", \"Instance\": {\"FeatureVector\": {" + featureVector + "}, \"GlobalParameters\":{\"level_mhist\": 300, \"level_shist\": 100, \"trend_mhist\": 300, \"trend_shist\": 100 }}}";
                var jsonBytes = Encoding.Default.GetBytes(jsonData);

                return wb.UploadDataTaskAsync(rrs, "POST", jsonBytes)
                    
                    .ContinueWith(
                    resp =>
                    {
                        var response = Encoding.Default.GetString(resp.Result);
#if DEBUG_LOG
                        Trace.TraceInformation("AzureML response: {0}...", response.Substring(0, Math.Min(100, response.Length)));
#endif

                        JavaScriptSerializer ser = new JavaScriptSerializer { MaxJsonLength = int.MaxValue };
                        var results = ser.Deserialize<List<string[]>>(response);

                        var presults = results.Select(AnomalyRecord.Parse);
                        return filterAnomaly(presults);
                    }
                    );
            }
        }
开发者ID:HenryRawas,项目名称:iothub-robotarm,代码行数:33,代码来源:Analyzer.cs

示例7: Upload

        /// <summary>
        /// Uploads the specified file to   the cloud.
        /// </summary>
        /// <param name="file">The full path to the desired .zip file.</param>
        private async Task<UploadResult> Upload(DS4Session session, CancellationToken ct)
        {
            string file = session.CompressedScanFile;
            string contentType = "application/x/7z-compressed";

            WebClient proxy;

            string result = string.Empty;

            // Step1: Get s3 signed URL
            proxy = new WebClient();

            // Gather data
            string fileName = Path.GetFileName(file);
            
            Dictionary<string, string> postDict = new Dictionary<string, string> {
                {"filename", fileName},
                {"file_type", contentType},
            };

            String postData = JSONHelper.Instance.Serialize(postDict);
            // Prepare request
            proxy.Headers["Content-Type"] = "application/json";
            proxy.Headers["Authorization"] = _authHeader;

            // Perform request            
            try
            {
                result = await proxy.UploadStringTaskAsync(this.BuildUri("s3/sign"), "POST", postData);
            }
            catch (WebException ex)
            {
                return new UploadResult { Success = false, Exception = ex };
            }

            ct.ThrowIfCancellationRequested();

            // Step 2: Upload to s3 signed PUT URL
            _s3Proxy = proxy = new WebClient();
            proxy.UploadProgressChanged += new UploadProgressChangedEventHandler(this.Progress);
            proxy.UploadDataCompleted += (s , e) => { if(ct.IsCancellationRequested) _canceled = true; };

            // Gather data
            Dictionary<string, string> response = JSONHelper.Instance.CreateDictionary(result);
            string url = response["signedUrl"];
            string key = response["key"];

            byte[] binaryData = File.ReadAllBytes(file);

            // Prepare headers
            proxy.Headers["Content-Type"] = contentType;

            // Prepare request
            Uri uri = new Uri(url, UriKind.Absolute);
            // Perform request
            try
            {
                byte[] uploadResponse = await proxy.UploadDataTaskAsync(uri, "PUT", binaryData);
            }
            catch (WebException ex)
            {
                
                Console.WriteLine(Uploader.GetErrorMsgFromWebException(ex));
                return new UploadResult { Success = false, Exception = ex, Canceled = _canceled };
            }

            ct.ThrowIfCancellationRequested();

            // Step 3: PostUpload and get returned BodyId
            proxy = new WebClient();

            //Assemble payload
            List<Dictionary<string, string> > artifacts = new List<Dictionary<string, string> >();
            artifacts.Add(new Dictionary<string, string> { 
                {"artifactsType","DS4Measurements"}
            });

            artifacts.Add(new Dictionary<string, string> { 
                {"artifactsType","DS4Alignment"}
            });

            DS4BodyRequest bodyRequest = new DS4BodyRequest("ds4_scan", key, artifacts);

            postData = JSONHelper.Instance.Serialize(bodyRequest);

            // Prepare request
            proxy.Headers["Content-Type"] = "application/json";
            proxy.Headers["Authorization"] = _authHeader;

            // Perform request
            try
            {
                result = await proxy.UploadStringTaskAsync(this.BuildUri("bodies/from_scan"), "POST", postData);
            }
            catch (WebException ex)
            {
//.........这里部分代码省略.........
开发者ID:shirshmx,项目名称:Monocle-Record-Rssdk,代码行数:101,代码来源:Uploader.cs

示例8: RunAsync

 public async Task<PortCheckResult> RunAsync()
 {
   var client = new WebClient();
   var data   = new JObject();
   data["instanceId"] = InstanceId.ToString("N");
   data["ports"] = new JArray(Ports);
   var succeeded = false;
   var stopwatch = new System.Diagnostics.Stopwatch();
   string response_body = null;
   try {
     stopwatch.Start();
     var body = System.Text.Encoding.UTF8.GetBytes(data.ToString());
     response_body = System.Text.Encoding.UTF8.GetString(
       await client.UploadDataTaskAsync(Target, body)
     );
     stopwatch.Stop();
     succeeded = true;
     var response = JToken.Parse(response_body);
     var response_ports = response["ports"].Select(token => (int)token);
     return new PortCheckResult(
         succeeded,
         response_ports.ToArray(),
         stopwatch.Elapsed);
   }
   catch (WebException) {
     succeeded = false;
     return new PortCheckResult(
         succeeded,
         null,
         stopwatch.Elapsed);
   }
   catch (Newtonsoft.Json.JsonReaderException) {
     succeeded = false;
     return new PortCheckResult(
         succeeded,
         null,
         stopwatch.Elapsed);
   }
 }
开发者ID:kumaryu,项目名称:peercaststation,代码行数:39,代码来源:PCPPortChecker.cs

示例9: probando4

        public static async void probando4()
        {
            using (var client = new WebClient())
            {

                byte[] archivo = System.IO.File.ReadAllBytes(@"C:\tesisData\dataset\rock\rock.00007.au");
                Uri address = new Uri("http://developer.echonest.com/api/v4/track/upload?api_key=ERYL0FA7VZ24XQMOO&filetype=au");


                Task<byte[]> task = client.UploadDataTaskAsync(address, "POST", archivo);
                byte[] a = await task;
                var responseString = Encoding.Default.GetString(a);

            }

        }
开发者ID:landeoas,项目名称:BusquedaSimilitud,代码行数:16,代码来源:PrincipalController.cs


注:本文中的System.Net.WebClient.UploadDataTaskAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。