【问题标题】:HTTP Post from c#.net [duplicate]来自 c#.net 的 HTTP Post [重复]
【发布时间】:2015-04-23 11:25:31
【问题描述】:

我们的第三方支付网关提供商仅支持 FORM POST 进行握手、支付和支付验证等。

为此,我们需要从 C#.NET 执行 POST。有人可以帮助我是否有任何 NUGET 包或示例可以实现这一目标?

我已经看过this,但没有找到优雅的:

【问题讨论】:

  • MSDN 文章中描述的解决方案有什么问题?
  • @stefankmitph 他实际上要求不同的解决方案。
  • @PatrikEckebrecht 是的,答案最高的重复问题提供了 3 种不同的解决方案。

标签: c# http-post form-post


【解决方案1】:

一种简单的方法是使用RestSharp

这是一个示例 POST 请求。

using RestSharp;

var client = new RestClient("http://example.com");
// client.Authenticator = new HttpBasicAuthenticator(username, password);

var request = new RestRequest("resource/{id}", Method.POST);
request.AddParameter("name", "value"); 
request.AddUrlSegment("id", "123"); 
// easily add HTTP Headers
request.AddHeader("header", "value");

// add files to upload (works with compatible verbs)
request.AddFile(path);

// execute the request
RestResponse response = client.Execute(request);

【讨论】:

  • 根据我的帖子,它不是 REST 或 SOAP 服务。它只是接受表单发布的 aspx 页面。对于初次握手,我们需要通过代码发布数据。
猜你喜欢
  • 2019-01-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-29
  • 2021-03-12
  • 2015-07-22
  • 1970-01-01
  • 2014-02-20
相关资源
最近更新 更多