Mas*_*ian 7 c# silverlight post
我的项目是silverlight navighation项目(IN-Browser)我想导航到一个Url,例如:
System.Windows.Browser.HtmlPage.Window.Navigate(new Uri(string.Format("http://{0}:
{1}/ReportProject.aspx#/Supplies/RequestGoods/RequestGoodsDashboard",
Application.Current.Host.Source.Host,
Application.Current.Host.Source.Port)), "_blank", "");
Run Code Online (Sandbox Code Playgroud)
并使用post方法向目标页面发送许多参数
我怎么能这样做?
你不能Navigate()仍然使用POST.Navigate相当于在地址栏中单击链接或键入URL,它会调用GET动词.
要使用POST,您可以使用Silverlight浏览器互操作以编程方式创建HTML <form>,将其action属性设置为正确的URL,将其target属性设置为"_blank",添加一些<input type="hidden">字段,设置其名称和值,然后再submit()使用表单.
// Get document and body
var doc = System.Windows.Browser.HtmlPage.Document;
var body = doc.Body;
// Create a <form> element and add it to the body
var newForm = doc.CreateElement("form");
newForm.SetAttribute("action", targetUrl);
newForm.SetAttribute("method", "post");
body.AppendChild(newForm);
// TODO: doc.CreateElement("input");
// TODO: SetAttribute("type", "hidden");
// TODO: SetAttribute("name", someName);
// TODO: SetAttribute("value", someValue);
// TODO: newForm.AppendChild()
newForm.Invoke("submit");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3055 次 |
| 最近记录: |