首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WebRequest来发布数据,但是隐藏字段呢?

WebRequest来发布数据,但是隐藏字段呢?
EN

Stack Overflow用户
提问于 2010-10-13 04:37:09
回答 1查看 3.2K关注 0票数 2

实际上,我需要将一些隐藏字段发送到页面,然后将其加载到浏览器窗口中。

这是根据第6页:http://www.docstoc.com/docs/10745827/Sage-Pay-Form-Protocol-and-Integration-Guidelines所述的SagePay窗体集成

我已经在使用WebRequest创建帖子了,但是我该如何发送他们需要的4个隐藏字段呢?

另外,如何将返回的html加载到浏览器中;该html来自SagePay,客户在其中输入他们的信用卡详细信息?

代码语言:javascript
复制
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;
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-10-13 04:41:55

只需将4个隐藏字段添加到postData字符串中。这可以在此方法中或在请求中即时完成。

“隐藏”方面仅在浏览器的GUI方面是隐藏的。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3918817

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档