Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>POST with WebView in Windows 8.1</h2> <p>Or even better, use <code>WebView.NavigateWithHttpRequestMessage(HttpRequestMessage requestMessage)</code>.</p> <p>You can use a <code>Windows.Web.Http.HttpRequestMessage</code> to set the HTTP method and the request content among other things.</p> <p>E.g.:</p> <pre><code>HttpRequestMessage request = new HttpRequestMessage( HttpMethod.Post, new Uri("http://localhost")); request.Content = new HttpStringContent( String.Format("user_id={0}&amp;session_id={1}", "Chinese", "food")); webView.NavigateWithHttpRequestMessage(request); </code></pre> <p>That would be equivalent to the following HTTP request:</p> <pre><code>POST / HTTP/1.1 Accept: text/html, application/xhtml+xml, */* Accept-Language: en-US,en;q=0.5 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; Touch; MASAJS; WebView/2.0; rv:11.0) like Gecko Accept-Encoding: gzip, deflate Host: localhost Content-Length: 31 Connection: Keep-Alive Cache-Control: no-cache user_id=Chinese&amp;session_id=food </code></pre> <h2>POST with WebView in Windows 8</h2> <p>For Windows 8, do it with JavaScript! </p> <ol> <li>Create a <code>&lt;form&gt;</code>, set the <code>action</code> to your destination URI and set the <code>method</code> to POST.</li> <li>Add two <code>&lt;input&gt;</code> and name them with the names you want, in this case <code>user_id</code> and <code>session_id</code>.</li> <li>Add a script that sets the inputs value and submit the form.</li> </ol> <p>E.g.:</p> <pre><code>protected override void OnNavigatedTo(NavigationEventArgs e) { webView.NavigateToString(@"&lt;html&gt; &lt;head&gt; &lt;script type='text/javascript'&gt; function doSomething(userIdValue, sessionIdValue) { document.getElementById('user_id').value = userIdValue; document.getElementById('session_id').value = sessionIdValue; document.getElementById('myForm').submit(); return 'Hello World!'; } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form id='myForm' action='http://localhost' method='post'&gt; &lt;input type='hidden' id='user_id' name='user_id' /&gt; &lt;input type='hidden' id='session_id' name='session_id' /&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt;"); } private void Button_Click(object sender, RoutedEventArgs e) { string result = webView.InvokeScript("doSomething", new string[] { "Chinese", "food" }); } </code></pre> <p>That would send a request like this:</p> <pre><code>POST / HTTP/1.1 Accept: text/html, application/xhtml+xml, */* Accept-Language: en-US,en;q=0.5 User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0; Touch; MASAJS; WebView/1.0) Content-Type: application/x-www-form-urlencoded Accept-Encoding: gzip, deflate Host: localhost Content-Length: 31 Connection: Keep-Alive Cache-Control: no-cache user_id=Chinese&amp;session_id=food </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload