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


C# HttpClient.Put方法代码示例

本文整理汇总了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()));
             }
         }
     }
 }
开发者ID:NickAndersonX,项目名称:xodb,代码行数:13,代码来源:GalleryPackageService.cs

示例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);
                }
            }
        }
开发者ID:philcockfield,项目名称:Open.TestHarness.SL,代码行数:15,代码来源:ServerProxy.cs

示例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();
        }
开发者ID:wangchunlei,项目名称:MyGit,代码行数:41,代码来源:Program.cs

示例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);
            }
        }
开发者ID:WindowsCommunicationFoundation,项目名称:WCF4-,代码行数:21,代码来源:Program.cs

示例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.");
                        }
                    }
                }
            }
        }
开发者ID:NickAndersonX,项目名称:xodb,代码行数:39,代码来源:RatingSynchronizer.cs

示例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;
        }
开发者ID:nXqd,项目名称:University_Projects,代码行数:13,代码来源:Student.cs

示例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>();
            }
        }
开发者ID:dataware,项目名称:geostore,代码行数:16,代码来源:Program.cs


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