Tag: http post

发布和重定向FROM Web Api

警告: 这个问题不是关于如何发布到Web Api,是如何从Web Api发布。 场景: 我的问题与Darin Dimitrov的回答有关: 如何在ASPNET Web API中重定向 并且似乎是一个重复的: Response.Redirect,它将数据发布到ASP.NET中的另一个URL,但考虑到问题已经过时(2008),我正在寻找可能WebApi是最新的答案。 使用Visual Studio 2012 Web Api 2.1 我通过控制器中的POST方法获取应用程序中的数据(是一个web api)。 到现在为止还挺好。 现在我想将这些数据(带有一些更改)发布到接受我的数据的外部站点(这已经过validation并且可以正常工作)。 对于这个过程,我尝试了两种方法: 使用带有javascript的“onload”事件提交的基本表单创建一个字符串。 从( 将数据POST到ASP.NET中的另一个URL的Response.Redirect )。 这是有效的,这就是我使用它的方式,但也许可以用一些更好的方法来代替。 使用client.PostAsync 。 我也可以使用它,但我不想显示对用户的响应,我想重定向他。 也许这可以适应重定向? 题: 如何在不使用“onload”变通方法的情况下重定向发送Post变量,或者在不等待响应的情况下调整“HttpClient”以进行重定向后? 考虑:我不发布任何代码,因为我的两个选项的实现已经很容易,我没有任何问题。

Windows窗体应用程序C#中的HTTP发布

我需要在C#中编写一个表单应用程序,通过HTTP POST将参数发送到url,然后获取响应。 我真的没有意识到从哪里开始,这有可能吗? 提前谢谢,加尔。

C#中的curl-F等价物

我试图在C#中使用HTTPClient对象向API发送一个post请求。 这是CURL命令: curl -X POST https://zzz.zzz.zzz/yyy -F Key=abcd -F media=@”audio.aac” 我写了以下代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Net.Http; using System.IO; using System.Net.Http.Headers; namespace Speech2Text { class Program { static void Main(string[] args) { curl().Wait(); } static async Task curl() { var client = new HttpClient(); //Create List of KeyValuePairs List<KeyValuePair> […]

如何将参数传递给WCF post方法(一个restful服务)

我正在开发基于WCFrest的服务。 我在我的服务中编写了Get和Post方法,并且当我输入URL(JSON格式)时,Get方法能够工作(获取数据)。 问题是,当我尝试对POST方法执行相同操作时,该URL正在导航到其他页面“找不到页面…”。 我知道POST方法需要表单提交来处理请求。 出于这个原因,我尝试了chrome扩展(Simple Rest客户端,Advanced Rest客户端,Post man rest客户端)和Fiddler。 这里我发布我的服务方法 – Get方法(接口方法声明)。 [OperationContract] [WebInvoke(Method = “GET”, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = “GetCategoryTypes/”)] List GetCategoryTypes(); 这是我的POST方法 [OperationContract] [WebInvoke(Method = “POST”, UriTemplate = “AddOrders/”, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)] int AddOrders(decimal amount, int tableID, DateTime orderDate, int […]

Post FromBody始终无效

我有一个新的API,我正在使用ASP.NET Core构建,我无法将任何数据POST到端点。 这是端点的样子: [HttpPost] [Route(“StudentResults”)] public async Task GetStudentResults([FromBody]List userSocs, [FromBody]int collegeId) { var college = await _collegeService.GetCollegeByID(collegeId); // var occupations = await _laborMarketService.GetOccupationProgramsBySocsAndCollege(userSocs, college); return Ok(); } 这就是我通过Postman发送的有效载荷如下所示: { “userSocs”: [ “291123”, “291171”, “312021”, “291071”, “152031”, “533011” ], “collegeId”: 1 } 我确保我将postman设置为POST,使用Content-Type application/json 。 我究竟做错了什么?

使用HTTP Post从Excel中插入SQL Server数据库中的数据

我想在Excel中单击“插入”按钮时将数据插入SQL Server数据库。 数据在单元格A2和B2中,这里是excel中“插入”按钮背后的代码: Dim HttpReq As New WinHttp.WinHttpRequest HttpReq.Open “POST”, “http://localhost:11121/Student/Insert/”, False HttpReq.Send “jsmith112” 这是我在VS中的Controller操作的代码: [HttpPost] public ActionResult Insert(string id) { try { student.AddToStudents(id); student.SaveChanges(); return RedirectToAction(“Index”); } catch { return View(); } } 这似乎没有用,有人能引导我完成这个吗? 提前致谢

如何使用method =“post”从表单中获取数据? 如何在我的控制器中请求数据?

我试图从我的HTML代码中获取数据,如“acquringCode”,“cardAcceptor”和“merchantId”。 我无法想象如何在我的控制器中获取该数据。 我知道它的request.form。 我相信我做错了。 有没有更简单的方法让我通过函数传递对象或每个名称作为参数? HTML $(document).ready(function () { $(“#SavetreventLocationLookupAddButton”).click(function () { $(“#addSaveTreventLocationLookup”).submit(); }); }); 添加Trevent位置查找 <form id="addSaveTreventLocationLookup" method="post" action="”> Trevent Location Lookup Detail Acquiring Institution Identification Code: Card Acceptor Identification Code: Merchant Id: Add Cancel 位指示 [HttpPost] [AuthorizeAttribute(AdminRoles = “AddTreventLocationLookup”)] public ActionResult AddSaveTreventLocationLookup() { try { string acquiringInstitutionIdentificationCode; //= Request.Form[“AcquiringInstitutionIdentificationCode”] ?? string.Empty; string cardAcceptorIdentificationCode;// […]

如何将数据发布到网站

我需要将数据发布到网站上。 所以我在C#.net中创建了一个小应用程序,在那里我打开这个网站并用我的数据库中的值填充所有控件(单选按钮,文本框,复选框等)。 我还在SUBMIT按钮上有一个点击事件。 然后应用程序等待10-15秒,然后将响应从网页复制到我的数据库。 如你所见,这真是一个繁忙的过程。 如果要上传数千条记录,则此应用程序需要更长时间(因为它等待响应的时间为15秒)。 有没有其他方式发布数据? 我正在寻找像所有字段连接其值并像上传数据流一样上传的东西。 如果网站是https而不是http,这将如何工作?

使用HttpWebRequest使用multipart / form-data POST数据/上传图像

我正在尝试使用ImageShack API上传图像。 要使用它,我应该使用multipart/form-data POST图像。 我这样做…… var postData = “”; var req = HttpWebRequest.Create(“http://www.imageshack.us/upload_api.php”); req.Method = “POST”; req.ContentType = “multipart/form-data”; postData += “key=my_key_here&”; postData += “type=base64&”; // get base64 data from image byte[] bytes = File.ReadAllBytes(@”D:\tmp\WpfApplication1\WpfApplication1\Images\Icon128.gif”); string encoded = Convert.ToBase64String(bytes); postData += “fileupload=” + encoded; byte[] reqData = Encoding.UTF8.GetBytes(postData); using (Stream dataStream = req.GetRequestStream()) { dataStream.Write(reqData, […]

IIS 7.5,Web服务和HTTP 405错误

我有一个Web服务,我在我的机器上托管。 我使用的是Windows 7和IIS 7.5。 问题 :当客户端尝试使用Web服务时,他/她会收到HTTP 405错误。 在IIS的日志文件中,我可以看到这被拒绝,因为不允许POST动词。 问题 :如何为这些请求允许POST动词? 我是否必须添加WSDL文件的映射? 如果我这样做,我该如何配置此映射? 我已经检查过,在现有的映射中,我对WSDL扩展没有任何帮助。 是否可能在IIS上设置另一个允许这些请求的东西? Web服务是使用WCF构建的。