navigate and post data from silverlight

后端 未结 1 859
余生分开走
余生分开走 2021-01-02 17:08

My project is silverlight navighation project (IN-Browser) I want to navigate to an Url such as :

System.Windows.Browser.HtmlPage.Window.Navigate(new Uri(str         


        
相关标签:
1条回答
  • 2021-01-02 18:04

    You cannot Navigate() and still use POST. Navigate is the equivalent of clicking a link or typing a URL in the address bar, which invokes the GET verb.

    To use POST, you could instead use the Silverlight browser interop to programmatically create an HTML <form>, set its action attribute to the correct URL, set its target attribute to "_blank", add some <input type="hidden"> fields, set their names and values and then submit() the form.

    // 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");
    
    0 讨论(0)
提交回复
热议问题