Windows 8 Store Apps Learning (61) Communication: HTTP, OAuth

Source: Internet
Author: User
Tags http post http request oauth xmlns

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.