我正在伪造一个使用webclient的表单帖子:
public static string SendHttpRequest(string url, string method, List<WebParameter> paramaters)
{
using(WebClient client = new WebClient())
{
client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
System.Collections.Specialized.NameValueCollection reqparm = new System.Collections.Specialized.NameValueCollection();
foreach (var param in paramaters)
{
reqparm.Add(param.name, param.value);
//reqparm.Add("param2", "escaping is already handled");
}
byte[] responsebytes = client.UploadValues(url, method, reqparm);
string responsebody = Encoding.UTF8.GetString(responsebytes);
return responsebody;
}
}
到目前为止它运作良好,但响应是一个html页面。我想将此页面嵌入到我的视图中。
我的控制器操作如下所示
string response = SendHttpRequest(purl,"POST",param);
ViewBag.Response = response;
return View();
在我看来,当我调用ViewBag.Response时,它向我显示原始html。这不是我想要的。我想显示页面。
我想我可以用iframe做到这一点,但不知道怎么做。
编辑:
预期的响应如下:
<!DOCTYPE html> <html> <head> <link rel='shortcut icon' type='image/x-icon' href='/test_paydirect/favicon.ico' /> <meta name="viewport" content="width=device-width, initial-scale = 1, maximum-scale=1, user-scalable=no" /> <title>WebPAY</title> <link href="/test_paydirect/Content/webpay?v=CSrAVoCR_RCkIRW_2W4qWDLY74gqncHw6gTHkYQDqPI1" rel="stylesheet"/> <script src="/test_paydirect/scripts/jquery?v=YDYC4uCmpbLIjqOyVNC_2sd9YbHnRonWjUni8iH6_Xo1"></script> </head> <body> <div id="outer-frame"> <div id="page-header"> <div id="account-header"> </div> </div> <!--page logo header starts--> <div id="page-logo-header" class=""> <div id="page
答案 0 :(得分:3)
您是否在视图中尝试过此操作?:
@Html.Raw(ViewBag.Response)
默认情况下,字符串将采用HTML编码,以防止脚本注入。