Tag: http post

取消’HttpClient’POST请求

我在Windows Phone 8应用程序上使用HttpClient.PostAsync()上传图像。 用户可以选择通过UI按钮取消此上传。 要取消POST请求,我设置了CancellationToken 。 但这不起作用。 在取消请求之后,我看到仍然看到我的代理中发生了上传,很明显该请求被忽略了。 我的代码: using (var content = new MultipartFormDataContent()) { var file = new StreamContent(stream); file .Headers.ContentDisposition = new ContentDispositionHeaderValue(“form-data”) { FileName = “filename.jpg”, }; file.Headers.ContentType = new MediaTypeHeaderValue(“image/jpeg”); content.Add(file); await httpclient.PostAsync(new Uri(“myurl”, UriKind.Absolute), content, cancellationToken); } 另请注意,我有CancellationTokenSource的CancellationToken 。 用户单击“取消”按钮后,将调用tokensource.Cancel() 。 此外,我的测试用例中的图像是1到2 MB(不是那么大)。 那么,有没有办法取消HttpClient POST请求?

重定向后HttpPost到ReturnURL

我正在编写一个ASP.NET MVC 2.0应用程序,要求用户在对项目进行投标之前登录。 我正在使用actionfilter来确保用户已登录,如果没有,则将它们发送到登录页面并设置返回URL。 下面是我在动作filter中使用的代码。 if (!filterContext.HttpContext.User.Identity.IsAuthenticated) { filterContext.Result = new RedirectResult(String.Concat(“~/Account/LogOn”,”?ReturnUrl=”,filterContext.HttpContext.Request.RawUrl)); return; } 在我的登录控制器中,我validation用户凭据,然后将其签名并重定向到返回URL FormsAuth.SignIn(userName, rememberMe); if (!String.IsNullOrEmpty(returnUrl)) { return Redirect(returnUrl); } 我的问题是,这将始终使用Get(HttpGet)请求,而我的原始提交是一个post(HttpPost),应该始终是一个post。 任何人都可以建议一种传递此URL的方法,包括HttpMethod或任何解决方法,以确保使用正确的HttpMethod?

如果在post后模型中的值发生更改,则表单仍会显示旧值

这种行为让我对自己的理智感到好奇。 我有一个表单有两个接受输入的地方,我们称之为ValueA和ValueB。 用户可以在任何一个和表单提交中输入值。 <%=Html.TextBox("ValueA", Model.ValueA, new Dictionary { { “onchange”, “$(‘#SubmitButton’).click(); return false;” }, }) %> <%=Html.TextBox("ValueB", Model.ValueB, new Dictionary { { “onchange”, “$(‘#SubmitButton’).click(); return false;” }, }) %> Controller Action看起来像这样: public ActionResult MyControllerAction(MyViewModel viewModel) { //做一些其他的事…… return PartialView(“MyPartialView”, viewModel); } ViewModel就是这样的: public class MyViewModel { private int _valueA; private int _valueB; public int ValueA […]

在ASP.NET MVC中使用POST传递变量

我试图在asp.net MVC中传递一个字符串变量。 我使用断点,所以我看到它确实转到控制器中的正确方法,但发布的变量等于null。 我的标记: @{ ViewBag.Title = “TestForm”; } TestForm @using (Html.BeginForm()) { } 我的控制器: public ActionResult TestForm() { return View(); } [HttpPost] public ActionResult TestForm(string testinput) { Response.Write(“[” + testinput + “]”); return View(); } 我将断点放在第二个TestForm方法中,testinput为null ….我错过了什么吗? 注意:我意识到大多数时候我将使用模型传递数据,但我想知道我也可以传递字符串。 作为同一问题的一部分,我如何传递几个变量? 我的控制器中的方法是这样的: [HttpPost] public ActionResult TestForm(string var1, var2) { }

Windows Phone 8中的简单HTTP POST

我有一个字符串,我需要在Windows Phone 8中POST。它看起来像这样: https://www.scoreoid.com/api/getPlayers?api_key=[apiKey]&game_id=[gameID]&response=xml&username=[username]&password=[password] 此字符串只返回另一个字符串(格式为XML,我稍后在我的代码中解析)。 我还没有像在Windows 8中那样找到一个简单的解决方案。 编辑:通过rciovati和HttpClient库的帮助找到我的问题的解决方案。 这是我的简单代码: var httpClient = new HttpClient(); return await httpClient.GetStringAsync(uri + “?” + post_data);

FromBody值为null

这是Asp.Net Webform应用程序 这是我的Apicontroller中的POST方法 public void Post([FromBody]string value) { } 我是小提琴后期流程。 我做了这样的实验。 但事实并非如此。 问题是什么。 你能帮我吗? 我试过了,我失败了。 public void Post(MyViewModel model) { string aa = model.Value; } public class MyViewModel { public string Value { get; set; } } 在提琴手: Request Body: Value=hakan

在C#.NET中通过HTTP发布的SOAP对象

我正在尝试在C#.NET中编写SOAP消息(包括头文件)以使用HTTP post发送到URL。 我想将其发送到的URL不是Web服务,它只接收SOAP消息以最终从中提取信息。 关于如何做到这一点的任何想法?

StringContent与FormUrlEncodedContent

我有一个URL我希望以data =“blahblahblah”的forms发布带有参数的主体。 但是,在这种情况下,我的“blahblahblah”是一个完整的XML,我将其简化为如下所示: 我可以通过以下方法找到使用HTTPClient FormUrlEncodedContent查找的工作。 var values = new List<KeyValuePair>(); values.Add(new KeyValuePair(“data”, XMLBody)); var content = new FormUrlEncodedContent(values); HttpResponseMessage sResponse = await sClient.PostAsync(action.URL, content).ConfigureAwait(false); 现在我想让它与StringContent一起使用。 基本上发送xml作为参数值的一部分,并且该xml包含“=” 。 下面的代码不起作用,因为我可以发布它,但服务器无法识别xml数据。 我在这里做错了吗? StringContent content = new StringContent(HttpUtility.UrlEncode(action.Body), Encoding.UTF8, “application/x-www-form-urlencoded”); HttpResponseMessage sResponse = await sClient.PostAsync(action.URL, content ).ConfigureAwait(false);

添加’System.Web.Http’命名空间时,找不到类型或命名空间名称’HttpGet’

我在MVC中有一个问题。 目前我在MVC工作,版本是MVC4。 我有2个ActionResult方法,见下文 [HttpGet] public ActionResult About() { ViewBag.Message = “Your app description page.”; return View(); } [HttpPost] public ActionResult About(ModelName ccc) { ViewBag.Message = “Your app description page.”; return View(); } 我们需要using System.Web.Mvc; [HttpPost]和[HttpGet]属性的命名空间。 所以我添加了using System.Web.Mvc; 控制器中的命名空间。 但我需要using System.Web.Http;添加另一个命名空间using System.Web.Http; 对于我的控制器中的httpsresponseexpectionerror handling。我在命名空间中添加了。 这时System.Web.Mvc; 不管用 。 我收到此错误: 无法找到类型或命名空间名称’HttpGet’ 。 为什么? HttpGet的System.Web.Mvc和System.Web.Http之间的任何关系?

在POST操作中更改ViewModel属性

我有这个POST动作: [HttpPost] public ActionResult GetReport(GetReportModel model) { if (!ModelState.IsValid) { return View(model); } return View(“GetReport”, new GetReportModel() { Identifier = “test”, Permission = true }); } 当我发布表单时,执行此操作后,生成的视图中没有任何更改。 我的意思是, Identifier的TextBox没有我在动作中设置的“测试”字符串值。 但是如果我清除ModelState ,View将显示新值: [HttpPost] public ActionResult GetReport(GetReportModel model) { if (!ModelState.IsValid) { return View(); } ModelState.Remove(“Identifier”); ModelState.Remove(“Permission”); return View(“GetReport”, new GetReportModel() { Identifier = “test”, Permission = […]