Introduced
Re-imagine the Windows 8 Store Apps Communication
HttpClient Overview
HTTP GET string
HTTP GET Stream
HTTP POST string
HTTP POST Stream
OAuth 2.0 Authenticated clients
Example
Service side for demonstrating HTTP traffic
Webserver/httpdemo.aspx.cs
* * used in response to HTTP request * * using System;
Using System.IO;
Using System.Threading; namespace WebServer {public partial class HttpDemo:System.Web.UI.Page {protected void Page_Load (object
sender, EventArgs e) {//stop for 3 seconds to facilitate the test of cancellation of HTTP request Thread.Sleep (3000);
var action = request.querystring["Action"]; Switch (action) {case "getString"://Response HTTP GET string Response.Write (
"Hello Webabcd");
Break Case "GetStream"://Response HTTP Get stream Response.Write ("Hello webabcd hello webabcd hello webabcd hel Lo webabcd Hello webabcd hello webabcd hello webabcd hello webabcd hello webabcd hello webabcd Hello webabcd
");
Break Case "poststring"://Response to HTTP Post string Response.Write (string. Format ("param1:{0}, Param2:{1}, Referrer:{2}", ReqUest.
form["param1"], request.form["param2"], request.urlreferrer));
Break Case "Poststream"://Response HTTP POST stream using (StreamReader reader = new StreamReader (request.input Stream)) {String BODY = reader.
ReadToEnd ();
Response.Write (Server.HTMLEncode (body));
} break;
Default:break;
} response.end (); }
}
}
1, through HttpClient, httprequestmessage, httpresponsemessage implementation of HTTP communication
Communication/http/summary.xaml
<page
x:class= "XamlDemo.Communication.HTTP.Summary"
xmlns= "http://schemas.microsoft.com/winfx/2006/ Xaml/presentation "
xmlns:x=" Http://schemas.microsoft.com/winfx/2006/xaml "
xmlns:local=" using: XamlDemo.Communication.HTTP "
xmlns:d=" http://schemas.microsoft.com/expression/blend/2008 "
xmlns:mc=" http://schemas.openxmlformats.org/markup-compatibility/2006 "
mc:ignorable=" D ">
<grid background=" Transparent ">
<stackpanel margin=" 0 0 0 ">
<textblock name=" lblmsg "fontsize=" 14.667 "/>
<button name= "btnpost" content= "http POST" click= "Btnpost_click_1" margin= "0 0 0"/> <button
Name = "Btncancel" content= "Cancel"
click= "btncancel_click_1" margin= "0 0 0"/>
</StackPanel>
</Grid>
</Page>