Httplistener listens for HTTP requests

Source: Internet
Author: User
Using System;
Using System. Collections. Generic;
Using System. LINQ;
Using System. text;
Using System. net;
Using System. net. Sockets;
Using System. IO;

Namespace Leleapphttplistener
{
/// <Summary>
/// Listen for HTTP requests by rhythmk
/// </Summary>
Class Program
{
Static Void Main ( String [] ARGs)
{
Listenerhttpurl ();

Console. readkey ();
}

Static Void Listenerhttpurl ()
{
String Url = " Http://admin2.rhytmk.t/rhythmk/ " ;
Using (Httplistener hlistener = New Httplistener ())
{
// Anonymous Access
Hlistener. authenticationschemes = authenticationschemes. Anonymous;
Hlistener. prefixes. Add (URL );
// Hlistener. prefixes. Add ("url2 ")
Hlistener. Start ();
Console. writeline ( " --- Start ---- " );
While ( True )
{
Httplistenercontext hlcontext = hlistener. getcontext ();
Hlcontext. response. statuscode = 200 ;
String Key = hlcontext. Request. querystring [ " Key " ];
If (! String . Isnullorempty (key ))
{
Console. writeline ( String . Format ( " The key is {0}, time: {1} " , Key, datetime. Now ));
}
// Close request
Hlcontext. response. Close ();

// OUTPUT response html Structure
// Using (streamwriter writer = new streamwriter (hlcontext. response. outputstream ))
// {
// Writer. writeline ("true ");
// Writer. Close ();
// Hlcontext. response. Close ();
// }
}
}
}

}
}

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.