使用GET方法访问网站
使用GET方法访问网站
服务器接收get参数
server.py
import flask
app = flask.Flask(__name__)
@app.route('/')
def index():
province = flask.request.args.get('province')
city = flask.request.args.get('city')
print(province, city)
return province+","+city debug=True
if __name__ == '__main__':
app.run()
client.py
import urllib.request
url = "http://127.0.0.1:5000"
province = "山东"
city = "青岛"
# 对汉字编码
province = urllib.parse.quote(province)
city = urllib.parse.quote(city)
# 拼接字符串
data = "province=" + province + "&city=" + city
response = urllib.request.urlopen(url+"?"+data)
data = response.read()
content = data.decode()
print(content) # try:
# # 模拟浏览器向服务器发送请求
# response = urllib.request.urlopen(url+"?"+data)
# data = response.read()
# content = data.decode()
# print(content)
# except urllib.error.HTTPError:
# print('HTTPError异常')
# except urllib.error.URLError:
# print('URLError异常')

客户端发送get请求
server.py
import flask
from flask import Flask app = Flask(__name__)
@app.route('/')
def index():
lang = flask.request.values.get("lang","")
if lang == "chinese":
html = "大家好"
else:
html = "hello"
return html app.debug = True
app.run()
client.py
import urllib.request
url = "http://127.0.0.1:5000"
response = urllib.request.urlopen(url+"?lang=english")
content = response.read()
print(content)
html = content.decode()
print(html)

中文字符串参数编码
Server.py
import flask
app = flask.Flask(__name__) @app.route('/')
def index():
dict = {"苹果": "apple", "桃子": "peach", "梨子": "pear"}
word = flask.request.values.get("word", "")
if word in dict.keys():
s = dict[word]
else:
s = "字典里无该词"
return s debug = True
if __name__ == '__main__':
app.run()
Client.py
import urllib.request
import urllib.parse url = "http://127.0.0.1:5000"
word = input("请输入中文:")
word = urllib.parse.quote(word)
response = urllib.request.urlopen(url+"?word="+word)
content = response.read()
html = content.decode("utf-8")
print(html)

Requests中的GET
server.py
import flask
app = flask.Flask(__name__) @app.route('/')
def index():
try: province = flask.request.values.get('province', "")
city = flask.request.values.get('city', "")
return province + "," + city
except Exception as e:
return str(str) debug = True
if __name__ == '__main__':
app.run()
client.py
import requests
url = "http://127.0.0.1:5000" try:
response = requests.get(url, params={"province": "山东", "city": "青岛"})
print(response.content)
print(response.text)
except Exception as e:
print(e)
使用GET方法访问网站的更多相关文章
- vue配置手机通过IP访问,Win10让局域网内其他电脑通过IP访问网站的方法
vue配置手机通过IP访问config/index.js// Various Dev Server settings host: '0.0.0.0', // can be overwritten by ...
- windows/linux VPS云服务器限制IP访问,限制别人的IP访问网站方法
服务器VPS云服务器如何限制IP访问,限制别人的IP访问网站的方法 windows主机IIS限制IP访问方法:首先打开IIS点击“网站”,右键属性,(如果仅给单个网站设置,请选择下边的站点,点右键“属 ...
- Apache禁止访问网站子目录的方法
在PHP网站开发中,基于WEB服务器和PHP网站程序代码的安全考虑,我们需要对相关的目录或者文件访问权限进行控制,以防止意外情况的发生,那么我们如何来实现这种功能呢?我们可以通过Apache来实现禁止 ...
- Windows Server 2008 R2 下配置证书服务器和HTTPS方式访问网站
http://www.cnblogs.com/zhongweiv/archive/2013/01/07/https.html 配置环境 了解HTTPS 配置CA证书服务器 新建示例网站并发布在IIS ...
- 配置Java SSL 访问网站证书
最近在开发 Java 访问 Azure ServiceBus 时遇到SSL证书问题,导致JAVA报错,不能正常访问,报错信息如下: javax.net.ssl.SSLException: Connec ...
- htaccess文件还可以被用来把访问网站的流量劫持到黑客的网站
看是否有文件上传操作(POST方法), IPREMOVED--[01/Mar/2013:06:16:48-0600]"POST/uploads/monthly_10_2012/view.ph ...
- 忘记常访问网站密码怎么办?教你如何查看浏览器已保存的密码,如何简单查看Chome浏览器保存的密码?
利用场景: 同事或朋友外出有事,电脑未锁屏离开座位.可以利用这一间隙,查看Ta在Chrome浏览器上保存的账号密码 查看逻辑: 当我们要查看Chrome浏览器上保存的密码时,点击显示,会弹出一个对话框 ...
- 通过ASP禁止指定IP和只允许指定IP访问网站的代码
过ASP禁止指定IP和只允许指定IP访问网站的代码,需要的朋友可以参考下. 一.禁止指定IP防问网站,并执行相应操作: 代码如下: <% Dim IP,IPString,VisitIP '设置I ...
- IIS7.0 Windows Server 2008 R2 下配置证书服务器和HTTPS方式访问网站
配置环境 Windows版本:Windows Server 2008 R2 Enterprise Service Pack 1 系统类型: 64 位操作系统 了解HTTPS 为什么需要 HTTPS ? ...
- 【ASP.NET】判断访问网站的客户端是PC还是手机
原文:[ASP.NET]判断访问网站的客户端是PC还是手机 主要就是通过客户端传递的User-agent来判断访问网站的客户端是PC还是手机,.NET中就是Request.ServerVariable ...
随机推荐
- [Go] golang 时间格式化 12小时制 与 24小时制
timestamp := int64(1591271169) # 12小时制 time.Unix(timestamp, 0).Format("2006-01-02 03:04:05" ...
- 阿里云OSS文件上传几种方法(主要是前端)
目录 零.准备 一.服务端签名后直传 1. 阿里云控制台配置 2. 后端接口开发(PHP) 3. 前端获取签名后上传 二.使用STS临时凭证进行上传 1. 后端接口开发(node) 2. 前端获取临时 ...
- OLAP系列之分析型数据库clickhouse主从副本模式(三)
一.测试单分片,单副本或多副本模式 # 1.停止集群 systemctl stop clickhouse-server # 修改配置文件 vim /etc/clickhouse-server/conf ...
- Solution - AGC060B
Link 简要题意:在 \(n \times m\) 的方格表中填入一些不超过 \(2^k-1\) 的数.考虑所有从左上角到右下角的最短路径,要求其中满足路径上数异或和为 \(0\) 的路径只有给定的 ...
- 文件上传--php user.ini详解
文件上传 参考文档:https://www.php.net/manual/zh/configuration.file.per-user.php 如果你的 PHP 以模块化运行在 Apache 里,则用 ...
- docker 安装 kafka+zookeeper,golang操作kafka
目录 docker-compose.yml go操作kafka producer 消费者 consumer 消费者 结合gin框架操作kafka go-queue操作kafka 环境: centos8 ...
- Nginx在Windows 10、Ubuntu16.04、Centos7下的安装
目录 一. Windows 10 安装nginx 二. Ubuntu16.04 安装apt nginx 三. Centos7 yum安装nginx 四. ubuntu/centos编译安装nginx ...
- Golang 爬虫01
目录 学习地址: 目录站: 爬虫概念: 工作流程: 百度贴吧爬虫实现: go实战代码 单进程 实现过程: 并发爬取 实现过程: 学习地址: https://www.bilibili.com/video ...
- linux打包压缩工具详解
linux打包压缩工具详解 目录 linux打包压缩工具详解 1.linux文件压缩工具 1.1 compress命令详解 1.2 gzip命令详解 1.3 bzip2命令详解 1.4 xz命令详解 ...
- 微信小程序关于小说类使用官方阅读器
https://doc.weixin.qq.com/doc/w3_AAcAYAbdAFwpM63n1R5SIat3aa4cX?scode=AJEAIQdfAAoYHVCBbdAG4A1QYmAFQ 上 ...