本文整理汇总了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;
}
}
}
示例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);
}
}
示例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);
}
}
}
}
*/
}
}
示例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);
}
}
示例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");
}
}
示例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", "");
}
}
示例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);
}
}
示例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;
}
}
示例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", "");
}
}
示例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;
}
}
示例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);
}
}
示例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));
}
}
示例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;
}
}
示例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));
}
示例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;
}
}