Python httpserver Server (beginner)

Source: Internet
Author: User

Use native Python developed Web server, entry level!

#!/usr/bin/python#-*-coding:utf-8-*-ImportOs#The OS module in the Python standard library contains common operating system featuresImportRe#Introducing Regular Expression ObjectsImportUrllib#used to encode URLs fromBasehttpserverImportHttpserver, Basehttprequesthandler#importing HTTP processing-related modules#custom handlers for handling HTTP requestsclassTesthttphandler (basehttprequesthandler):#Handling GET Requests    defDo_get (self):#Get URL        Print 'url=', Self.path#page Output Template stringTemplatestr =" "" "self.protocal_version='http/1.1'  #Set Protocol versionSelf.send_response (200)#Setting the response status codeSelf.send_header ("Welcome","contect")#Setting the response headerself.end_headers () self.wfile.write (TEMPLATESTR)#Output Response Content        #Start the service functiondefStart_server (port): Http_server= Httpserver (("', int (port)), Testhttphandler) Http_server.serve_forever ()#set up listening and receiving requests#os.chdir (' static ') #改变工作目录到 static directoryStart_server (8000)#Start the service, listen on port 8000

Python httpserver Server (beginner)

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.