本文整理汇总了C#中Microsoft.Http.HttpClient.Put方法的典型用法代码示例。如果您正苦于以下问题:C# HttpClient.Put方法的具体用法?C# HttpClient.Put怎么用?C# HttpClient.Put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Http.HttpClient
的用法示例。
在下文中一共展示了HttpClient.Put方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdatePackage
public void UpdatePackage(Package packageToUpdate) {
using (var client = new HttpClient(_serviceRoot.Value)) {
HttpContent content = HttpContentExtensions.CreateDataContract(packageToUpdate);
string uri = _serviceUriBuilder.BuildServiceUri(ServiceConstants.PackageServiceName, packageToUpdate.Id,
packageToUpdate.Version);
using (HttpResponseMessage response = client.Put(uri, content))
{
if (response.StatusCode != HttpStatusCode.OK) {
_orchardServices.Notifier.Error(T(response.ReadContentAsStringWithoutQuotes()));
}
}
}
}
示例2: Put
public HttpResult Put(string urlPath, HttpContent content)
{
// Setup initial conditions.
if (urlPath.IsNullOrEmpty(true)) return null;
urlPath = FormatPath(urlPath);
// Pass PUT call to the target server.
using (var client = new HttpClient(GetBaseUrl()))
{
using (var response = client.Put(urlPath, content))
{
return ProcessResponse(response);
}
}
}
示例3: ListAllContacts
static void ListAllContacts()
{
using (HttpClient client = new HttpClient("http://localhost:9000/api/contacts/"))
{
//Get
Console.WriteLine("Get-Method Test...");
using (var request = new HttpRequestMessage("GET", "Get/1/name"))
{
request.Headers.Accept.Add("application/json");
using (var response = client.Send(request))
{
var status = response.StatusCode;
Console.WriteLine("Status Code: {0}", status);
var result = response.Content.ReadAsString();
Console.WriteLine("Content: {0}", result);
}
}
//Post
Console.WriteLine("Post-Method Test...");
HttpContent content = HttpContentExtensions
.CreateJsonDataContract(new List<Contact>
{
new Contact{Name = "王春雷"},
new Contact{ContactId = 1,Name = "老张"}
});
content.LoadIntoBuffer();
using (var response = client.Put("Filter/1/王春雷", content))
{
response.EnsureStatusIsSuccessful();
response.Content.LoadIntoBuffer();
var result = response.Content.ReadAsJsonDataContract<List<Contact>>();
//var serializer = new JavaScriptSerializer();
//var con=serializer.Deserialize<List<Contact>>(result);
result.ForEach(r => Console.WriteLine(r.ToString()));
}
}
Console.ReadKey();
}
示例4: Main
static void Main(string[] args)
{
using(HttpClient restClient = new HttpClient())
{
HttpResponseMessage resp = restClient.Get("http://localhost:1234/CarPool");
resp.EnsureStatusIsSuccessful();
Console.WriteLine(resp.Headers.ToString());
var result = resp.Content.ReadAsString();
Console.WriteLine(result);
string newCar = "<Car xmlns=\"http://schemas.datacontract.org/2004/07/Wrox\"><Make> Seat </Make> <Name> Leon </Name><Seats> 5 </Seats> <Type> Sport Car </Type> </Car> ";
restClient.Put("http://localhost:1234/CarPool/Leon", "application/xml", HttpContent.Create(newCar));
Console.WriteLine(resp.StatusCode);
resp = restClient.Get("http://localhost:1234/CarPool");
resp.EnsureStatusIsSuccessful();
var result1 = resp.Content.ReadAsString();
Console.WriteLine(result1);
}
}
示例5: ExecuteThreadSafeAction
protected override void ExecuteThreadSafeAction() {
DateTime? lastRatingSyncTimeSetting = _orchardServices.WorkContext.CurrentSite.As<GallerySettingsPart>().LastRatingSyncTime;
DateTime lastRatingSyncTime = lastRatingSyncTimeSetting.HasValue ? lastRatingSyncTimeSetting.Value : new DateTime(1900, 1, 1);
IEnumerable<ResultRecord> resultRecords = _resultRecordRepository.Fetch(rr => rr.ContentType == "Package" && rr.FunctionName == new Average().Name
&& rr.CreatedUtc > lastRatingSyncTime);
DateTime utcNow = _clock.UtcNow;
var packageRatingAggregates = new List<PackageVersionRatings>();
foreach (var resultRecord in resultRecords) {
ResultRecord closureResultRecord = resultRecord;
var package = _packageService.Get(p => p.ContentItemRecord.Id == closureResultRecord.ContentItemRecord.Id).SingleOrDefault();
if (package != null) {
var packageRatingAggregate = new PackageVersionRatings
{
PackageId = package.PackageID,
PackageVersion = package.PackageVersion,
RatingAverage = closureResultRecord.Value,
RatingCount = closureResultRecord.Count
};
packageRatingAggregates.Add(packageRatingAggregate);
}
}
if (packageRatingAggregates.Any()) {
using (var client = new HttpClient(_serviceRoot.Value)) {
HttpContent content = HttpContentExtensions.CreateDataContract(packageRatingAggregates);
_nonceCache.Nonce = Guid.NewGuid().ToString();
string uri = string.Format("{0}/{1}/{2}", ServiceConstants.PackageServiceName, "UpdatePackageRatings", _nonceCache.Nonce);
using (HttpResponseMessage response = client.Put(uri, content)) {
if (response.StatusCode == HttpStatusCode.OK) {
_typeCaster.CastTo<GallerySettingsPart>(_orchardServices.WorkContext.CurrentSite).LastRatingSyncTime = utcNow;
}
else {
Logger.Error("Call to UpdatePackageRatings on Gallery.Server failed.");
}
}
}
}
}
示例6: Update
public static bool Update(Student student)
{
var http = new HttpClient(ServiceURL);
var uri = "student/update";
// get return string from server
var res = http.Put(uri, HttpContent.Create(JsonConvert.SerializeObject(student)));
var stream = res.Content.ReadAsStream();
var result = new StreamReader(stream).ReadToEnd();
if (result == "true")
return true;
return false;
}
示例7: UpdateLocation
static Location UpdateLocation(HttpClient client, Location location)
{
Console.WriteLine("Updating location '{0}':", location.id);
Console.WriteLine();
string updateUri = "Locations/" + location.id.ToString();
HttpContent content = HttpContentExtensions.CreateJsonDataContract(location);
Console.WriteLine("Request");
WriteOutContent(content);
using (HttpResponseMessage response = client.Put(updateUri, content))
{
response.EnsureStatusIsSuccessful();
return response.Content.ReadAsJsonDataContract<Location>();
}
}