Python 重定向 响应头
来源:互联网 发布:在淘宝上搜春药怎么搜 编辑:程序博客网 时间:2024/05/29 11:44
请求头:GET /articles/2001/ HTTP/1.1Host: 192.168.137.3:9000User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2Accept-Encoding: gzip, deflateCookie: csrftoken=YbGeEfNIf2Hcl6TF5wdi2WhvJ1JMGvmuBfH91cNsJLC4WO3TFCv84O0spWsZqXeT; sessionid=besfz007xaeknwdgt1lr6mm4dcib4oz2Connection: keep-aliveUpgrade-Insecure-Requests: 1响应头:HTTP/1.0 302 FoundDate: Mon, 27 Nov 2017 10:01:37 GMTServer: WSGIServer/0.1 Python/2.7.3X-Frame-Options: SAMEORIGINContent-Type: text/html; charset=utf-8Location: http://www.baidu.com/Content-Length: 0http://192.168.137.3:9000/articles/2017/curl "http://192.168.137.3:9000/articles/2017/" --1.0 -H "Host: 192.168.137.3:9000" -H "User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" -H "Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2" --compressed -H "Cookie: csrftoken=YbGeEfNIf2Hcl6TF5wdi2WhvJ1JMGvmuBfH91cNsJLC4WO3TFCv84O0spWsZqXeT; sessionid=besfz007xaeknwdgt1lr6mm4dcib4oz2" -H "Connection: keep-alive" -H "Upgrade-Insecure-Requests: 1"此时有了302 重定向python 获取重定向信息,重定向信息位于响应头import httplibdef check_web_server(host,port,path): h=httplib.HTTPConnection(host,port) h.request('GET',path) print h.host print h.port resp = h.getresponse() print 'status =', resp.status print 'reason =', resp.reason print 'HTTP Headers:' for hdr in resp.getheaders(): print ' %s: %s' % hdrcheck_web_server('192.168.137.3','9000','/articles/2017/')C:\Python27\python.exe C:/Users/TLCB/PycharmProjects/untitled/mycompany/thread/p12.py192.168.137.39000status = 302reason = FoundHTTP Headers: content-length: 0 server: WSGIServer/0.1 Python/2.7.3 location: http://www.baidu.com/ date: Mon, 27 Nov 2017 11:06:54 GMT x-frame-options: SAMEORIGIN content-type: text/html; charset=utf-8node2:/django/mysite/news#cat views.py# -*- coding: utf-8 -*-from __future__ import unicode_literalsfrom django.shortcuts import renderfrom django.http import HttpResponse# Create your views here.from django.shortcuts import render,render_to_response,redirectfrom .models import Articlefrom django.http import HttpResponse, HttpResponseNotFoundimport datetimefrom django.views.decorators.http import require_http_methods,require_GETfrom django.http import HttpResponseRedirectfrom django.shortcuts import renderimport osdef year_archive(request, year): print '-------------------------' print year print '-------------------------' response = "You're looking at first the results of question %s." #return HttpResponse(response % year) return redirect('http://www.baidu.com/')
阅读全文
0 0
- Python 重定向 响应头
- 004_Http之response响应头-01重定向
- 处理HTTP响应(响应码、响应头、请求重定向、自动刷新/跳转)
- 处理HTTP响应(响应码、响应头、请求重定向、自动刷新/跳转)
- 处理HTTP响应(响应码、响应头、请求重定向、自动刷新/跳转)
- 004_Http之response响应头-02定时刷新(定时重定向)
- Response-响应头、自定义重定向、文字\IO输出、文件下载
- python 的重定向
- [python]重定向输出
- python重定向
- python 重定向
- python重定向
- python 输出重定向
- python print 重定向
- Python输入输出重定向
- python flask重定向
- Python接口-重定向
- python 获取响应头
- Cannot evaluate tensor using `eval()`: No default session is registered. Use `with sess.as_default()
- [jQuery] 添加读取csv文件的扩展
- windows系统 安装MongoDB 32位
- java设计模式之代理模式
- 《Thing in java》上塑造型的笔记
- Python 重定向 响应头
- X64与X86各个类型的长度
- SpringBoot 项目如何在tomcat容器中运行
- tar命令的详细解释
- 微信红包订单存储架构变迁的最佳实践
- Spread Studio跨平台表格控件集发布V11版本,速度更快、内存更省
- Kotlin 开发
- YYCache学习
- 第14周项目1(6)- 验证算法 堆排序