Tag: http post

C#Web API POST参数FromBody始终为null

我已经在网上搜了好几个小时,并尝试了StackOverflow上描述的许多不同的解决方案。 我之前已经问过类似的问题,但没有一个答案或评论对我有用。 问题:我有一个.NET Web API,它有一个带有一些参数的Post方法。 其中一个参数是一个复杂的对象,应该从正文中读取(即JSON)。 但是,此对象始终为null 。 这是我的代码: // POST api/worksheets/post_event/true/false [Route(“post_event/{newWorksheet}/{eindEvent}”)] [HttpPost] public Event Post(bool newWorksheet, bool eindEvent, [FromBody] Event eventData) { return eventData; } 要明确:eventData是始终为null的对象。 布尔值被正确读取。 完整的请求正文是: POST http://localhost:5000/api/worksheets/post_event/true/false Content-Type: application/json {“Persnr”:1011875, “WorksheetId”:null, “Projectnr”:81445, “Uursoort”:8678, “Tijd”:{“09-08-2016 9:25”}} 作为参考,这是Event-class: public class Event { public long Persnr { get; set; } public int WorksheetId […]

如何将大量数据传递到我的Web API应用程序?

我在Web API控制器中有这个代码: [Route(“{unit}/{begindate}/{enddate}”)] [HttpPost] public void Post(string unit, string begindate, string enddate, [FromBody] string stringifiedjsondata) { List _produceUsageList = JsonConvert.DeserializeObject<List>(stringifiedjsondata); string _unit = unit; string _begindate = String.Format(“{0}01”, HyphenizeYYYYMM(begindate)); string _enddate = GetEndOfMonthFor(enddate); string appDataFolder = HttpContext.Current.Server.MapPath(“~/App_Data/”); string htmlStr = ConvertProduceUsageListToHtml(_produceUsageList); string htmlFilename = string.Format(“produceUsage_{0}_{1}_{2}.html”, _unit, _begindate, _enddate); string fullPath = Path.Combine(appDataFolder, htmlFilename); File.WriteAllText(fullPath, htmlStr); […]

如何在asp.net应用程序中从jquery设置HttpPost端点

我想尝试一个Fine Uploader jQuery示例。 基本上它只是一种从客户端页面上传文件到Web服务器的方法。 有一个关于如何在项目的GitHub页面上设置服务器端文件流的示例。 如何从脚本调用此HttpPost endpoint ? 简单的jQuery示例如下所示: $(document).ready(function () { $(‘#jquery-wrapped-fine-uploader’).fineUploader({ request: { endpoint: ‘WhatToWriteHere??’ }, debug: true }); }); 那你在endpoint什么? 我想它会像Namespace.Namespace.ClassName.UploadMethod() ,但我一直在随便摆弄它,但不能让它工作。 使用Firebug进行调试时,出现以下错误: 405 Method Not Allowed [FineUploader] xhr – server response received for 0 The HTTP verb POST used to access path ‘/FineUploaderTest/Uploadfolder’ is not allowed. 任何的想法?

HttpClient上传MultipartFormData来玩2框架

我在使用RestSharp客户端的Windows Phone 8项目中有以下代码: public async Task DoMultiPartPostRequest(String ext, JSonWriter jsonObject, ObservableCollection attachments) { var client = new RestClient(DefaultUri); // client.Authenticator = new HttpBasicAuthenticator(username, password); var request = new RestRequest(ext, Method.POST); request.RequestFormat = DataFormat.Json; request.AddParameter(“json”, jsonObject.ToString(), ParameterType.GetOrPost); // add files to upload foreach (var a in attachments) request.AddFile(“attachment”, a.FileBody, “attachment.file”, a.ContType); var content = await client.GetResponseAsync(request); […]

ModelBinding:MVC4 / C中的POST数据(可能来自Ruby)#

我们正在与chargify http://www.chargify.com集成,我需要在我们的MVC4 / C#服务器中处理来自Chargify的webhooks。 Chargify以(ruby)方式发送POST数据 – 子对象在方括号中分隔,如下所示: POST /1ffaj2f1 HTTP/1.1 X-Chargify-Webhook-Signature: 526ccfd9677668674eaa6ba5d447e93a X-Chargify-Webhook-Id: 11238622 User-Agent: Ruby Host: requestb.in Content-Type: application/x-www-form-urlencoded Content-Length: 5159 Connection: close Accept-Encoding: gzip, deflate Accept: */*; q=0.5, application/xml id=11238622&event=payment_success&payload[subscription][activated_at]=2013-05-22%2001%3A25%3A20%20-0400&payload[subscription][balance_in_cents]=0&… 问题是在.NET端,默认模型绑定器不喜欢方括号[ ] ,而是期望子对象以点缀符号分隔,如abcd=value 我有什么选择让模型绑定器工作? 我能想到以下几点: 使用委托处理程序挂钩请求,读取req主体并将[]替换为点(。)。 然而,这至少感觉有点冒险 编写一个可以与[]一起使用的自定义模型绑定器 – 希望能够以某种方式委托给默认处理程序。 不知道怎么回事 – 但是很想听到一些想法。 只需在Action中使用formcollection参数即可。 处理表单集合键以基于键形成递归字典。 这也意味着我必须处理整个字符串(日期,ids等等) 什么是最好的方式,我该如何去做。

从HttpPost Asp.Net MVC方法返回保存的文件

我有一个Asp.Net MVC项目,在其中的一页上,用户可以将加载的数据编辑到表中(更改图像,字符串,项目顺序等)。 完成所有编辑后,客户端按下“下载”按钮,并将生成的xml文件保存在其硬盘驱动器上,以便将来进行下一次操作。 所以我有一个简单的HTML格式: {{data.Items[$index].Id}} 此表单数据通过angularJs函数调用发送,如下所示: $scope.sendForm = function () { // some preparations to send image data through json for (var i = 0; i < $scope.data.Items.length; i++) { $scope.data.Items[i].ImageAsString = $scope.data.Items[i].Image; } $http.post("Download", { array: $scope.data }) .success(function (responseData) { console.log(responseData); }) .error(function (responseData) { console.log("Error !" + responseData); }); }; 调用此函数后,准备好的http post请求发送到asp.net […]

在C#中用代码隐藏创建和发布表单的最佳方法

我正在使用webforms,我需要创建一个http form并将其发布到我的一个客户的支付网关。 我正在使用显示在母版页中的用户控件,但是他们已经在页面上有一个现有的 ,所以我很确定我无法添加另一个。 从后面的代码中用C#创建和发布表单的最佳实践方法是什么? 目前我有以下内容: var nvc = new System.Collections.Specialized.NameValueCollection { {“EWAY_ACCESSCODE”, ewayResponse.AccessCode}, {“EWAY_CARDNAME”, txtCcName.Text}, {“EWAY_CARDNUMBER”, txtCcNumber.Text}, {“EWAY_CARDEXPIRYMONTH”, ddlCcExpMonth.SelectedValue}, {“EWAY_CARDEXPIRYYEAR”, ddlCcExpYear.SelectedValue}, {“EWAY_CARDCVN”, txtCcv.Text} }; var client = new WebClient(); client.UploadValues(ewayResponse.FormActionURL, nvc); 这确实有效,但有没有更好/替代的方法呢?

使用C#测试网站

伙计们, 我需要完成一些复杂的网络爬行。 简单的目标:登录页面,在某些文本字段中输入一些值,单击“提交”,然后从检索到的页面中提取一些值。 什么是最好的方法? 一些unit testing第三方lib? 在C#中手动爬行? 也许有一个特别准备好的lib? 还有其他方法吗? 这需要在Web应用程序中完成。 非常感谢您的帮助。

使用Web服务HTTP Post

我正在使用ServiceStack来使用Web服务。 标题是: POST /SeizureWebService/Service.asmx/SeizureAPILogs HTTP/1.1 Host: host.com Content-Type: application/x-www-form-urlencoded Content-Length: length jsonRequest=string 我正在尝试使用此代码使用它: public class JsonCustomClient : JsonServiceClient { public override string Format { get { return “x-www-form-urlencoded”; } } public override void SerializeToStream(ServiceStack.ServiceHost.IRequestContext requestContext, object request, System.IO.Stream stream) { string message = “jsonRequest=”; using (StreamWriter sw = new StreamWriter(stream, Encoding.Unicode)) { sw.Write(message); } // […]

从HttpListenerRequest获取表单数据

我有一个HttpListenerRequest,它是从发布的html 启动的。 我需要知道如何获取发布的表单值+上传的文件。 有没有人知道一个例子来节省我为自己做的时间? 我有一个谷歌,但没有找到任何使用。