生成控制器HTTP POST请求 [英] Generate http post request from controller

查看:168
本文介绍了生成控制器HTTP POST请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

原谅我,如果这是一个愚蠢的问题。我不是很有经验的Web编程。 我实现我的.NET MVC应用程序的支付部分。该组件进行交互与外部的支付服务。支付服务接受以下表格HTTP POST请求

Forgive me if this is a stupid question. I am not very experienced with Web programming. I am implementing the payment component of my .net mvc application. The component interacts with an external payment service. The payment service accepts http post request in the following form

http://somepaymentservice.com/pay.do?MerchantID=xxx&Price=xxx&otherparameters

我知道这是死容易做到在视图中添加的一种形式。不过,我不希望我的意见来处理与第三方的参数。我想我的看法将信息提交给我的控制器,控制器生成所需的URL,然后发出请求。以下是伪code。

I know this is dead easy to do by adding a form in View. However, I do not want my views to deal with third party parameters. I would like my view to submit information to my controller, then controller generates the required url and then send out the request. Following is the pseudo code.

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult PayForOrder(OrderForm order)
{
    var url = _paymentService.GetUrlFromOrder(order);
    SendPostRequest(url);
    return View("FinishedPayment");
}

是否有可能这样做?请问C#有内置的库来生成http请求? 提前致谢。

Is it possible to do so? Does c# have built-in library to generate http request? Thanks in advance.

推荐答案

您将要使用的 HttpWebRequest的类。请务必将方法属性设置为张贴 - 这里是一个例子

You'll want to use the HttpWebRequest class. Be sure to set the Method property to post - here's an example.

这篇关于生成控制器HTTP POST请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆