本文整理汇总了C#中System.Net.Http.HttpClient.PatchAsync方法的典型用法代码示例。如果您正苦于以下问题:C# HttpClient.PatchAsync方法的具体用法?C# HttpClient.PatchAsync怎么用?C# HttpClient.PatchAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Http.HttpClient
的用法示例。
在下文中一共展示了HttpClient.PatchAsync方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PatchAsync
public static async Task<String> PatchAsync(HttpClient client, String apiUrl, List<APIRequest> requestBody)
{
var responseBody = String.Empty;
var jsonRequest = JsonConvert.SerializeObject(requestBody);
var content = new StringContent(jsonRequest, Encoding.UTF8, "application/json-patch+json");
using (HttpResponseMessage response = await client.PatchAsync(apiUrl, content))
{
response.EnsureSuccessStatusCode();
responseBody = await response.Content.ReadAsStringAsync();
}
return responseBody;
}
示例2: UpdateMatchInfo
public async Task UpdateMatchInfo()
{
HttpClient httpClient = new HttpClient();
Uri uri = new Uri(DataSource.host + "match/" + this.id.ToString() + "?access_token=" + DataSource.accessToken);
List<KeyValuePair<string, string>> pairsToSend = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("goals1", this.goals1.ToString()),
new KeyValuePair<string, string>("goals2", this.goals2.ToString()),
new KeyValuePair<string, string>("penalty1", this.penalty1.ToString()),
new KeyValuePair<string, string>("penalty2", this.penalty2.ToString()),
new KeyValuePair<string, string>("start_at", this.start_at),
new KeyValuePair<string, string>("place", this.place),
};
var content = new FormUrlEncodedContent(pairsToSend);
var response = await httpClient.PatchAsync(uri, content);
try
{
response.EnsureSuccessStatusCode();
}
catch (Exception ex)
{
//objectStatus = (int)DataSource.status.needUpdate;
throw new Exception(ex.Message);
//return false;
}
string result = await response.Content.ReadAsStringAsync();
//JsonObject jsonObject = JsonObject.Parse(result);
//if (jsonObject.Count == 0)
//{
// return false;
//}
//else
//{
// this.id = (int)jsonObject["id"].GetNumber();
//}
// objectStatus = (int)DataSource.status.ok;
// await DataSource.RefreshYellowCardsCollectionAsync(Match_idValue);
//return true;
}
示例3: Patch
public async Task<HttpStatusCode> Patch()
{
HttpClient httpClient = new HttpClient();
Uri uri = new Uri(DataSource.host + "goal/" + this.id.ToString() + "?access_token=" + DataSource.accessToken);
List<KeyValuePair<string, string>> pairsToSend = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("match_id", this.match_id.ToString()),
new KeyValuePair<string, string>("team_id", this.team_id.ToString()),
new KeyValuePair<string, string>("player_id", this.player_id.ToString()),
new KeyValuePair<string, string>("assistant_id", this.assistant_id.ToString()),
new KeyValuePair<string, string>("is_penalty", this.is_penalty.ToString().ToLower()),
new KeyValuePair<string, string>("is_autogoal", this.is_autogoal.ToString().ToLower()),
new KeyValuePair<string, string>("minute", this.minute.ToString()),
new KeyValuePair<string, string>("addition_minute", this.addition_minute.ToString()),
};
var content = new FormUrlEncodedContent(pairsToSend);
var response = await httpClient.PatchAsync(uri, content);
try
{
response.EnsureSuccessStatusCode();
}
catch (Exception ex)
{
objectStatus = (int)DataSource.status.needUpdate;
throw new Exception(ex.Message);
}
string result = await response.Content.ReadAsStringAsync();
JsonObject jsonObject = JsonObject.Parse(result);
objectStatus = (int)DataSource.status.ok;
return response.StatusCode;
}
示例4: Patch
public async Task<bool> Patch()
{
HttpClient httpClient = new HttpClient();
Uri uri = new Uri(DataSource.host + "match_player/" + this.id.ToString() + "?access_token=" + DataSource.accessToken);
List<KeyValuePair<string, string>> pairsToSend = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("match_id", this.match_id.ToString()),
new KeyValuePair<string, string>("team_id", this.team_id.ToString()),
new KeyValuePair<string, string>("player_id", this.player_id.ToString()),
new KeyValuePair<string, string>("teamsheet", this.teamsheet.ToString()),
new KeyValuePair<string, string>("is_capitan", this.is_capitan.ToString().ToLower()),
new KeyValuePair<string, string>("is_goalkeeper", this.is_goalkeeper.ToString().ToLower()),
};
var content = new FormUrlEncodedContent(pairsToSend);
var response = await httpClient.PatchAsync(uri, content);
try
{
response.EnsureSuccessStatusCode();
}
catch (Exception ex)
{
objectStatus = (int)DataSource.status.needUpdate;
throw new Exception(ex.Message);
return false;
}
string result = await response.Content.ReadAsStringAsync();
JsonObject jsonObject = JsonObject.Parse(result);
if (jsonObject.Count == 0)
{
return false;
}
else
{
// this.id = (int)jsonObject["id"].GetNumber();
}
objectStatus = (int)DataSource.status.ok;
return true;
}
示例5: Patch
public async Task<bool> Patch()
{
HttpClient httpClient = new HttpClient();
Uri uri = new Uri(DataSource.host + "yellow_card/" + this.id.ToString() + "?access_token=" + DataSource.accessToken);
List<KeyValuePair<string, string>> pairsToSend = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("match_id", this.match_id.ToString()),
new KeyValuePair<string, string>("team_id", this.team_id.ToString()),
new KeyValuePair<string, string>("player_id", this.player_id.ToString()),
new KeyValuePair<string, string>("minute", this.minute.ToString()),
new KeyValuePair<string, string>("addition_minute", this.addition_minute.ToString()),
new KeyValuePair<string, string>("note", this.note),
};
var content = new FormUrlEncodedContent(pairsToSend);
var response = await httpClient.PatchAsync(uri, content);
try
{
response.EnsureSuccessStatusCode();
}
catch (Exception ex)
{
objectStatus = (int)DataSource.status.needUpdate;
throw new Exception(ex.Message);
return false;
}
string result = await response.Content.ReadAsStringAsync();
JsonObject jsonObject = JsonObject.Parse(result);
if (jsonObject.Count == 0)
{
return false;
}
else
{
// this.id = (int)jsonObject["id"].GetNumber();
}
objectStatus = (int)DataSource.status.ok;
await DataSource.RefreshYellowCardsCollectionAsync(Match_idValue);
return true;
}
示例6: Patch
public async Task<bool> Patch(int MatchId)
{
HttpClient httpClient = new HttpClient();
Uri uri = new Uri(DataSource.host + "match/" + MatchId.ToString() + "/addition?access_token=" + DataSource.accessToken);
List<KeyValuePair<string, string>> pairsToSend = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("starthour", this.starthour.ToString()),
new KeyValuePair<string, string>("startminute", this.startminute.ToString()),
new KeyValuePair<string, string>("endhour", this.endhour.ToString()),
new KeyValuePair<string, string>("endminute", this.endminute.ToString()),
new KeyValuePair<string, string>("half_time_minutes", this.half_time_minutes.ToString()),
new KeyValuePair<string, string>("attendance", this.attendance.ToString()),
new KeyValuePair<string, string>("match_number", this.match_number.ToString()),
};
var content = new FormUrlEncodedContent(pairsToSend);
var response = await httpClient.PatchAsync(uri, content);
try
{
response.EnsureSuccessStatusCode();
}
catch (Exception ex)
{
objectStatus = (int)DataSource.status.needUpdate;
return false;
}
string result = await response.Content.ReadAsStringAsync();
JsonObject jsonObject = JsonObject.Parse(result);
if (jsonObject.Count == 0)
{
return false;
}
else
{
// this.id = (int)jsonObject["id"].GetNumber();
}
objectStatus = (int)DataSource.status.ok;
return true;
}
示例7: Send
private static async Task<RestResponse> Send(CancellationToken ct, string method, string url, string json, Guid appKey, Guid token, int timeoutInMinutes)
{
using (HttpClient httpClient = new HttpClient())
{
httpClient.Timeout = new TimeSpan(0, timeoutInMinutes, 0); // 1 minute timeout
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.Add("user-agent", UserAgent());
if (appKey != Guid.Empty)
httpClient.DefaultRequestHeaders.Add("appkey", appKey.ToString());
if (token != Guid.Empty)
httpClient.DefaultRequestHeaders.Add("token", token.ToString());
Coordinate location = UserLocation();
if (location != null)
{
httpClient.DefaultRequestHeaders.Add("latitude", location.Latitude.ToString(CultureInfo.InvariantCulture));
httpClient.DefaultRequestHeaders.Add("longitude", location.Longitude.ToString(CultureInfo.InvariantCulture));
}
HttpResponseMessage response = new HttpResponseMessage();
try
{
if (method == "POST")
response = await httpClient.PostAsync(url, new StringContent(json, Encoding.UTF8, "application/json"), ct);
else if (method == "PUT")
response = await httpClient.PutAsync(url, new StringContent(json, Encoding.UTF8, "application/json"), ct);
else if (method == "PATCH")
response = await httpClient.PatchAsync(url, new StringContent(json, Encoding.UTF8, "application/json"), ct);
if (response.IsSuccessStatusCode)
{
try
{
var data = response.Content.ReadAsStringAsync().Result;
return new RestResponse(data);
}
catch (Exception)
{
throw new Exception(AppResources.ApiErrorPopupMessageUnknownError);
}
}
else
{
string errorResponseString = response.Content.ReadAsStringAsync().Result;
Debug.WriteLine(errorResponseString);
if (!String.IsNullOrEmpty(errorResponseString))
{
ErrorResponseModel errorResponse = null;
try
{
errorResponse = JsonConvert.DeserializeObject<ErrorResponseModel>(errorResponseString);
return new RestResponse(errorResponse);
}
catch (Exception) { }
}
if (response.StatusCode == HttpStatusCode.NotFound)
{
return new RestResponse(new Exception(AppResources.ApiErrorPopupMessageNotFound));
}
else if (response.StatusCode == HttpStatusCode.BadRequest)
{
return new RestResponse(new Exception(AppResources.ApiErrorPopupMessageBadRequest));
}
else if (response.StatusCode == HttpStatusCode.InternalServerError)
{
return new RestResponse(new Exception(AppResources.ApiErrorPopupMessageInternalServerError));
}
else
return new RestResponse(new Exception(AppResources.ApiErrorPopupMessageUnknownError));
}
}
catch (TaskCanceledException)
{
if (ct.IsCancellationRequested)
return new RestResponse(new Exception(AppResources.ApiErrorTaskCancelled));
return new RestResponse(new Exception(AppResources.ApiErrorPopupMessageTimeout));
}
catch (Exception)
{
return new RestResponse(new Exception(AppResources.ApiErrorPopupMessageUnknownError));
}
}
}
示例8: Patch
public static async void Patch(string url, System.Net.Http.HttpContent wiPostDataContent, JSONReturnCallBack callBack)
{
string responseString = String.Empty;
try
{
using (HttpClient client = new System.Net.Http.HttpClient())
{
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json-patch+json"));
client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Basic", Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(getConnectionDetails())));
using (System.Net.Http.HttpResponseMessage response = client.PatchAsync(SetURL(url), wiPostDataContent).Result)
{
response.EnsureSuccessStatusCode();
string ResponseContent = await response.Content.ReadAsStringAsync();
responseString = ResponseContent;
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
Console.ReadLine();
}
callBack(responseString, String.Empty);
}