python 接收蓝牙网关http请求失败 浏览器却成功(已解决)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhuisaozhang1292/article/details/85320763

完全可以测通的(是因为防火墙的问题) 

原因:开启了防火墙在本地是可以测通的  外面的机器是访问不了我的电脑的

解决办法:关闭防火墙就可以了

第一种方法

from http.server import BaseHTTPRequestHandler
from http.server import HTTPServer
from socketserver import ThreadingMixIn
 
hostIP = '10.33.4.31'
portNum = 1883
class mySoapServer( BaseHTTPRequestHandler ):
    print('mySoapServer')
    def do_head( self ):
        print('do_head')
        pass
   
    def do_GET( self ):
        print('do_GET')
        try:
            self.send_response( 200, message = None )
            
            self.send_header( 'Content-type', 'text/html' )
            self.end_headers()
            res = '''
           <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
           <HTML>
           <HEAD><META content="IE=5.0000" http-equiv="X-UA-Compatible">
           <META content="text/html; charset=gb2312" http-equiv=Content-Type>
           </HEAD>
           <BODY>
           Hi, www.perlcn.com is a good site to learn python!
           </BODY>
           </HTML>
           '''
            self.wfile.write( res.encode( encoding = 'utf_8', errors = 'strict' ) )
        except IOError:
            self.send_error( 404, message = None )
   
    def do_POST( self ):
        print('do_POST')
        try:
            self.send_response( 200, message = None )
            
            self.send_header( 'Content-type', 'text/html' )
            self.end_headers()
            res = '''
           <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
           <HTML>
           <HEAD><META content="IE=5.0000" http-equiv="X-UA-Compatible">
           <META content="text/html; charset=gb2312" http-equiv=Content-Type>
           </HEAD>
           <BODY>
           Hi, www.perlcn.com is a good site to learn python!
           </BODY>
           </HTML>
           '''
            self.wfile.write( res.encode( encoding = 'utf_8', errors = 'strict' ) )
        except IOError:
            self.send_error( 404, message = None )
 
class ThreadingHttpServer( ThreadingMixIn, HTTPServer ):
    pass
     
myServer = ThreadingHttpServer( ( hostIP, portNum ), mySoapServer )
myServer.serve_forever()
myServer.server_close()

输出:

mySoapServer
do_GET
10.33.4.31 - - [28/Dec/2018 13:42:59] "GET /myapps HTTP/1.1" 200 -
do_GET
10.33.4.31 - - [28/Dec/2018 13:43:00] "GET /myapps HTTP/1.1" 200 -
10.33.4.31 - - [28/Dec/2018 13:43:24] "GET /myapps HTTP/1.1" 200 -
do_GET
10.33.4.31 - - [28/Dec/2018 13:43:25] "GET /myapps HTTP/1.1" 200 -
do_GET

第二种方法

import tornado.ioloop
import tornado.web
import msgpack

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, get")
        print('get')
    def post(self):
        package=self.request.files['chunk'][0]['body'];
        #print(payloads);
        print('post')
        print(msgpack.unpackb(package,use_list=False, raw=False));
    
application = tornado.web.Application([
    (r"/", MainHandler),])
 
if __name__ == "__main__":
    application.listen(1883,'10.33.4.31')
    tornado.ioloop.IOLoop.instance().start()

猜你喜欢

转载自blog.csdn.net/zhuisaozhang1292/article/details/85320763