草庐IT

mh_execute_header

全部标签

c# - 为 WebClient 请求设置 User-Agent header

为WindowsPhone7的WebClient请求设置User-Agentheader的正确方法是什么?我找到了2个选项,但不确定哪一个是正确的。考虑WebClient对象:WebClientclient=newWebClient();我看到了2个选项:使用以下方法设置用户代理:client.Headers["User-Agent"]="myUserAgentString";使用WebHeaderCollection设置用户代理:WebHeaderCollectionheaders=newWebHeaderCollection();headers[HttpRequestHeader.

c# - 无法在 HttpResponseMessage header 上设置 Content-Type header ?

我正在使用ASP.NETWebApi。我正在我的一个Controller中创建一个PUT方法,代码如下所示:publicHttpResponseMessagePut(intidAssessment,intidCaseStudy,stringvalue){varresponse=Request.CreateResponse();if(!response.Headers.Contains("Content-Type"))response.Headers.Add("Content-Type","text/plain");response.StatusCode=HttpStatusCode.O

c# - Async PartialView 导致 "HttpServerUtility.Execute blocked..."异常

我有一个试图检索IEnumerable的部分View使用异步从数据库...方法publicstaticclassPostService{publicstaticintPostsPerPage=50;publicstaticasyncTask>GetRecentAsync(intpage=0){returnawaitentityFrameworkDbContext.Posts.ToListAsync();}}局部ViewpublicasyncTaskRecent(intpage=0){returnPartialView(awaitPostService.GetRecentAsync(pa

c# - 在 HttpWebRequest 中添加自定义 header

我需要向HttpWebRequest对象添加一些自定义header。如何将自定义header添加到WindowsPhone7中的HttpWebRequest对象。 最佳答案 您将Headers属性与字符串索引一起使用:request.Headers["X-My-Custom-Header"]="the-value";根据MSDN,这从以下时间开始可用:通用Windows平台4.5.NETFramework1.1可移植类库银光2.0WindowsPhoneSilverlight7.0WindowsPhone8.1https://msd

c# - 如何在 WebApi 中添加和获取 Header 值

我需要在WebApi中创建一个POST方法,这样我就可以将数据从应用程序发送到WebApi方法。我无法获取header值。这里我在应用程序中添加了header值:using(varclient=newWebClient()){//SettheheadersoitknowswearesendingJSON.client.Headers[HttpRequestHeader.ContentType]="application/json";client.Headers.Add("Custom","sample");//Maketherequestvarresponse=client.Uploa

c# - "ClickOnce does not support the request execution level ' 需要管理员。 '"

所以我正在编写一个需要访问注册表的应用程序。我没有触及任何build设置,希望在添加其他内容(例如描述或名称)之前让它正常工作。出乎意料的是,我收到一个不会消失的错误。ClickOnce不支持请求执行级别“requireAdministrator”。现在,我还没有接触过此应用程序中的ClickOnce。我所做的只是包含一个请求这些权限的list文件。我现在的问题是这个错误不会消失,我无法编译我的程序。关于做什么的任何建议?(旁注:我要sleep了,所以明天下午我会检查一下)。 最佳答案 编辑:这条评论也给出了一个很好的答案。Clic

c# - 使用 System.Net.WebRequest 时无法设置某些 HTTP header

当我尝试在WebRequest对象上添加HTTPheader键/值对时,出现以下异常:Thisheadermustbemodifiedusingtheappropriateproperty我已经尝试使用Add()方法向Headers集合添加新值,但我仍然遇到相同的异常。webRequest.Headers.Add(HttpRequestHeader.Referer,"http://stackoverflow.com");我可以通过将WebRequest对象转换为HttpWebRequest并设置诸如httpWebReq.Referer="http://stackoverflow.com

c# - 设置HttpClient的Authorization Header

我有一个用于RESTAPI的HttpClient。但是我在设置授权header时遇到问题。我需要将header设置为我在执行OAuth请求时收到的token。我看到一些.NET代码建议如下,httpClient.DefaultRequestHeaders.Authorization=newCredential(OAuth.token);但是,WinRT中不存在Credential类。有人知道如何设置授权header吗? 最佳答案 所以方法如下,httpClient.DefaultRequestHeaders.Authorizatio

c# - 如何为 HttpClient 请求设置 Content-Type header ?

我正在尝试根据我正在调用的API的要求设置HttpClient对象的Content-Typeheader。我尝试像下面这样设置Content-Type:using(varhttpClient=newHttpClient()){httpClient.BaseAddress=newUri("http://example.com/");httpClient.DefaultRequestHeaders.Add("Accept","application/json");httpClient.DefaultRequestHeaders.Add("Content-Type","application

javascript - 为什么我的 JavaScript 代码会收到 "No ' Access-Control-Allow-Origin' header is present on the requested resource"错误,而 Postman 却没有?

Modnote:ThisquestionisaboutwhyXMLHttpRequest/fetch/etc.onthebrowseraresubjecttotheSameAccessPolicyrestrictions(yougeterrorsmentioningCORBorCORS)whilePostmanisnot.Thisquestionisnotabouthowtofixa"No'Access-Control-Allow-Origin'..."error.It'saboutwhytheyhappen.Pleasestopposting:CORSconfigurationsfo