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


C# WebClient.UploadStringTaskAsync方法代码示例

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


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

示例1: GetAuthenticationData

        public async Task<string> GetAuthenticationData(Dictionary<string, string> authenticationFields)
        {
            string username = authenticationFields[Field_Username];
            string password = authenticationFields[Field_Password];

            using (WebClient client = new WebClient())
            {
                client.Headers.Set("Content-Type", "application/json");
                client.Headers.Add(HttpRequestHeader.Authorization, $"Basic {Base64Encode(username + ":" + password)}");

                string json = await client.UploadStringTaskAsync($"{BitlyBaseUrl}/oauth/access_token", $"grant_type=password&username={username}&password={password}");
                if (json.StartsWith("{"))
                {
                    json = json.Replace(@"""data"": [ ], ", string.Empty);
                    JsonResponse data = JsonConvert.DeserializeObject<JsonResponse>(json);
                    if (data.status_txt == "OK")
                    {
                        return data.data.url;
                    }
                    else
                    {
                        throw new Exception(data.status_txt);
                    }
                }
                else
                {
                    return json;
                }
            }
        }
开发者ID:Gordon-Beeming,项目名称:Url-Quick-Short,代码行数:30,代码来源:BitlyPlugin.cs

示例2: Register

        public async void Register(UtsData data)
        {
            string json = JsonConvert.SerializeObject(data);
   
            Log.Info("Register", json);

           // Request Address of the API    
            string url = Server.url + "api/student/register";

           String result = null;
        
               using (WebClient wc = new WebClient())
               {
                
                wc.Headers[HttpRequestHeader.ContentType] = "application/json; charset=utf-8";
                wc.Headers.Add("AppKey", "66666");


                result = await wc.UploadStringTaskAsync(new Uri(url), json);
                   

                Log.Info("Register SUCCESS", result);
                HomeController loginController = new HomeController();
                await loginController.login(data.StudentId);

            }

              

        }
开发者ID:HamzaTariq95,项目名称:HELPSProject,代码行数:30,代码来源:RegisterController.cs

示例3: SendEvent

        async public Task SendEvent()
        {
            using (var client = new WebClient()) {
                client.Headers[HttpRequestHeader.ContentType] = "application/json";

                await client.UploadStringTaskAsync(sseUri, "POST", JsonConvert.SerializeObject(this));
                /* exception handling? what would we even do...
                try {
                    result = (await client.UploadStringTaskAsync(new Uri(url), "POST", json));
                }
                catch (WebException exception) {
                    string responseText;

                    if (exception.Response != null) {
                        var responseStream = exception.Response.GetResponseStream();

                        if (responseStream != null) {
                            using (var reader = new StreamReader(responseStream)) {
                                responseText = reader.ReadToEnd();
                                Debug.WriteLine(responseText);
                            }
                        }
                    }
                }
                */
            }
        }
开发者ID:Ell,项目名称:M800-Visualizer,代码行数:27,代码来源:GamesenseEvent.cs

示例4: SendNotification

 public async void SendNotification(string channelURI, string payload, NotificationType type = NotificationType.Raw)
 {
     if (WNSAuthentication.Instance.oAuthToken.AccessToken != null && !WNSAuthentication.Instance.IsRefreshInProgress)
     {
         using (var client = new WebClient())
         {
             SetHeaders(type, client);
             try
             {
                 await client.UploadStringTaskAsync(new Uri(channelURI), payload);
             }
             catch (WebException webException)
             {
                 if (webException?.Response != null)
                     HandleError(((HttpWebResponse)webException.Response).StatusCode, channelURI, payload);
                 Debug.WriteLine(String.Format("Failed WNS authentication. Error: {0}", webException.Message));
             }
             catch (Exception)
             {
                 HandleError(HttpStatusCode.Unauthorized, channelURI, payload);
             }
         }
     }
     else
     {
         StoreNotificationForSending(channelURI, payload);
     }
 }
开发者ID:openpeer,项目名称:ChatterBox,代码行数:28,代码来源:PushNotificationSender.cs

示例5: PostRequest

 private async static Task<string> PostRequest(string url)
 {
     using (var client = new WebClient())
     {
         client.Headers.Add("user-agent", "my own code");
         client.Headers.Add("content-type", "x-www-form-urlencoded");
         return await client.UploadStringTaskAsync(url, "test=value");
     }
 }
开发者ID:shayim,项目名称:Programming-DotNet,代码行数:9,代码来源:Program.cs

示例6: Delete

 public async Task Delete(string storageKey)
 {
     var uri = _uriFormatter.FormatUri(storageKey);
     _logger.Debug("Deleting blob {0} from {1}", storageKey, uri);
     using (var webClient = new WebClient())
     {
         await webClient.UploadStringTaskAsync(uri, "DELETE", "");
     }
 }
开发者ID:AtmosphereMessaging,项目名称:Cumulus,代码行数:9,代码来源:AzureBlobStorageHttpClient.cs

示例7: ApiProcessAsync

 public static async Task<string> ApiProcessAsync(string method, string parameter)
 {
     using (WebClient wc = new WebClient())
     {
         wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
         wc.Encoding = System.Text.Encoding.UTF8;
         return await wc.UploadStringTaskAsync(new Uri(Param.ApiUrl + method), parameter + "&apiKey=" + Param.ApiKey);
     }
 }
开发者ID:PowerDD,项目名称:PowerBackend,代码行数:9,代码来源:Util.cs

示例8: mput

        private async Task<string> mput(string topic, IEnumerable<string> messages)
        {
            var path = string.Format("{0}/mput?topic={1}", baseUriString, topic);
            var data = string.Join("\n", messages);

            using (var http = new WebClient())
            {
                var resp = await http.UploadStringTaskAsync(path, "POST", data);
                return resp;
            }
        }
开发者ID:xzoth,项目名称:NSQnet,代码行数:11,代码来源:NSQUtil.cs

示例9: Delete

        public async Task Delete(string storageKey)
        {
            if (storageKey == null) throw new ArgumentNullException("storageKey");

            var uri = _uriFormatter.FormatUri(storageKey);
            _logger.Debug("Deleting blob {0} from {1}", storageKey, uri);
            using (var webClient = new WebClient())
            {
                await webClient.UploadStringTaskAsync(uri, "DELETE", "");
            }
        }
开发者ID:Joshscorp,项目名称:Nimbus,代码行数:11,代码来源:AzureBlobStorageHttpClient.cs

示例10: put

        private async Task<string> put(string topic, string message)
        {
            var path = string.Format("{0}/put?topic={1}", baseUriString, topic);
            var data = message;

            using (var http = new WebClient())
            {
                var resp = await http.UploadStringTaskAsync(path, "POST", data);
                return resp;
            }
        }
开发者ID:xzoth,项目名称:NSQnet,代码行数:11,代码来源:NSQUtil.cs

示例11: DoRequest

 public static async Task DoRequest(BaseEvent @event, int port)
 {
     var url = string.Format("http://localhost:{0}/API/Message/NewMessage", port);
     var message = _serializer.Serialize<BaseEvent>(@event);
     using (WebClient client = new WebClient())
     {
         client.Encoding = Encoding.UTF8;
         client.Headers["Content-Type"] = "application/json; charset=utf-8";
         await client.UploadStringTaskAsync(new Uri(url), "POST", message);
     }
 }
开发者ID:PQ4NOEH,项目名称:.NET-recipes,代码行数:11,代码来源:MessageRequestHelper.cs

示例12: CallServer

        public async Task<string> CallServer(string path, object postData)
        {
            EnsureInitialized();

            string url = $"{BASE_URL}:{BasePort}/{path.ToLowerInvariant()}";

            using (WebClient client = new WebClient())
            {
                return await client.UploadStringTaskAsync(url, JsonConvert.SerializeObject(postData));
            }
        }
开发者ID:dan-kane,项目名称:WebAnalyzer,代码行数:11,代码来源:NodeServer.cs

示例13: PostJson

		public static async Task<string> PostJson(string url, string jsonData)
		{
			using(var wc = new WebClient())
			{
				wc.Encoding = Encoding.UTF8;
				wc.Headers.Add(HttpRequestHeader.ContentType, "application/json");

				var response = await wc.UploadStringTaskAsync(new Uri(url), jsonData);

				return response;
			}
		}
开发者ID:natorius,项目名称:Hearthstone-Deck-Tracker,代码行数:12,代码来源:ImportingHelper.cs

示例14: DownloadDataAsync

        internal static async Task<string> DownloadDataAsync(string method, string baseUrl, string data, string contentType, string authHeader)
        {
            var client = new WebClient();
            if (!String.IsNullOrEmpty(contentType)) client.Headers["Content-Type"] = contentType;
            if (!String.IsNullOrEmpty(authHeader)) client.Headers["Authorization"] = authHeader;

            if (method == "POST")
            {
                return await client.UploadStringTaskAsync(new Uri(baseUrl), data);
            }

            return await client.DownloadStringTaskAsync(new Uri(baseUrl));
        }
开发者ID:JamieKitson,项目名称:flickrnet-experimental,代码行数:13,代码来源:FlickrResponder45.cs

示例15: Post

        //POST /api/automate HTTP/1.1
        //Host: automatewebui.azurewebsites.net
        //Cache-Control: no-cache
        //Content-Type: application/x-www-form-urlencoded
        //
        //EmailAddress=jm_aba%40ahoo.com&Location=Lehliu&AgresivityRate=99
        public async Task<string> Post(ClientStatistics clientStatistics)
        {
            try
            {
                var data = _encoder.Encode(clientStatistics);

                var client = new WebClient();
                client.Headers[HttpRequestHeader.ContentType] = _encoder.ContentType;
                return await client.UploadStringTaskAsync(new Uri(_uri), "POST", data);
            }
            catch (Exception e)
            {
                return e.Message;
            }
        }
开发者ID:stonemonkey,项目名称:AutoMate,代码行数:21,代码来源:WebServiceProxy.cs


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