zoukankan      html  css  js  c++  java
  • python使用requests发送application/x-www-form-urlencoded请求数据

        def client_post_formurlencodeddata_requests(request_url,requestJSONdata):
            #功能说明:发送以form表单数据格式(它要求数据名称(name)和数据值(value)之间以等号相连,与另一组name/value值之间用&相连。例如:parameter1=12345&parameter2=23456。)请求到远程服务器,并获取请求响应报文。该请求消息头要求为:{"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}。
            #输入参数说明:接收请求的URL;请求报文数据,格式为name1=value1&name2=value2
            #输出参数:请求响应报文       
            import requests
    
            requestJSONdata=str(requestJSONdata).replace("+", "%2B")
            requestdata=requestJSONdata.encode("utf-8")
            head = {"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", 'Connection': 'close'}
            
            print '客户端请求JSON报文数据为(客户端 --> 服务端):
    ',requestdata
            
            #客户端发送请求报文到服务端
            r = requests.post(request_url,data=requestdata,headers=head)
            
            #客户端获取服务端的响应报文数据
            responsedata=r.text
            print '服务端的响应报文为(客户端 <--服务端): ',responsedata
            print "get the status: ",r.status_code
               
            #返回请求响应报文
            return responsedata
    

      

  • 相关阅读:
    虔诚的墓主人:组合数+数据结构
    DZY Loves Math II:多重背包dp+组合数学
    集合计数 :容斥原理
    「一本通 6.6 练习 8」礼物
    [bzoj3529][Sdoi2014]数表
    [专题总结]AC自动机
    6/14考试总结
    [无用]LNC李纳川的日常NC操作
    Linux下基本操作
    [ bzoj2820] YY的GCD
  • 原文地址:https://www.cnblogs.com/apple2016/p/9983844.html
Copyright © 2011-2022 走看看