生成控制器HTTP POST请求控制器、HTTP、POST

由网友(偶尔温顺)分享简介:原谅我,如果这是一个愚蠢的问题。我不是很有经验的Web编程。我实现我的.NET MVC应用程序的支付部分。该组件进行交互与外部的支付服务。支付服务接受以下表格HTTP POST请求Forgive me if this is a stupid question. I am not very experienced w...

原谅我,如果这是一个愚蠢的问题。我不是很有经验的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.

阅读全文

相关推荐

最新文章