python post请求中Content-Typ为application/x-www-form-urlencoded; charset=UTF-8 解决方案

复制代码
# -*- coding: utf-8 -*-
import requests
import json
from urllib import parse
import quotes



def  GtgLogin(UserName,phone,CurrentAddress):
    print("开始请求")
    header = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36',
        'Referer': 'http://61.183.175.130/sunxf/gtghj/index.html',
         'X - Requested - With': 'XMLHttpRequest',
         'Accept': 'application / json, text / javascript, * / *; q = 0.01',
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}

    postUrl = 'http://61.183.175.130/sunxf/gtghj/do/write.php?action=save'
    data='{"FromName":"gtghj","UserName":"%s","UserSex":"1","UserPhoneNo":"%s","UserMailbox":"","CurrentAddress":"test城","LetterTitle":"test。","IsPublic1":"1"}'%(UserName,phone)

    post_data1= {'json':data}
    ###### 转换x-www-form-urlencoded
    Data =parse.urlencode(post_data1)
    r = requests.post(postUrl, data=Data, headers=header)
    print( r.text.encode("utf-8").decode("unicode_escape"))


if __name__ == "__main__":
    GtgLogin('刘先生','1111','武汉市高新技术开发区佛祖岭和昌光谷未来城C区')
复制代码

python实现Content-Type类型为application/x-www-form-urlencoded发送POST请求

:

Data =parse.urlencode(post_data1)

 

posted @   马里亚纳仰望星空  Views(2873)  Comments(0Edit  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
点击右上角即可分享
微信分享提示