我基本上需要将一些隐藏字段发布到页面,我需要将其加载到 浏览器窗口。
这是针对第 6 页的 SagePay 表单集成: http://www.docstoc.com/docs/10745827/Sage-Pay-Form-Protocol-and-Integration-Guidelines
我已经在使用 WebRequest 创建 POST,但我该如何发送他们需要的 4 个隐藏字段?
此外,我如何将返回的 html 加载到浏览器中;这个 html 来自 SagePay,客户可以在其中输入他们的信用卡详细信息?
public string SendRequest(string url, string postData)
{
var uri = new Uri(url);
var request = WebRequest.Create(uri);
var encoding = new UTF8Encoding();
var requestData = encoding.GetBytes(postData);
request.ContentType = "application/x-www-form-urlencoded";
request.Method = "POST";
request.Timeout = (300 * 1000); //TODO: Move timeout to config
request.ContentLength = requestData.Length;
using (var stream = request.GetRequestStream())
{
stream.Write(requestData, 0, requestData.Length);
}
var response = request.GetResponse();
string result;
using (var reader = new StreamReader(response.GetResponseStream(), Encoding.ASCII))
{
result = reader.ReadToEnd();
}
return result;
}
最佳答案
只需将 4 个隐藏字段添加到 postData 字符串中。这可以在此方法中或在请求中即时完成。
“隐藏”方面仅在浏览器中的 GUI 方面隐藏。
关于c# - WebRequest 到 POST 数据但是隐藏字段呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3918817/