zoukankan      html  css  js  c++  java
  • python使用requests发送text/plain报文数据

        def client_post_text_plain_data_requests(self,request_url,textpalindata,headerdict={}):
            #功能说明:以text/plain形式发送请求报文到指定的地址并获取请求响应报文
            #输入参数说明:接收请求的URL,请求报文数据,待添加到请求头中的字段值组成的字典
            #输出参数:请求响应报文
            #by xiaocc[20180709]        
    
            #默认请求头
            head={"Content-Type":"text/plain; charset=UTF-8", 'Connection': 'close'} 
    
            print u'请求头待更新的数据:',headerdict,u'该数据类型为:',type(headerdict)
            #比对输入的header与默认的head,根据输入要求更新请求头
            if headerdict=='{}':#若未传入更新的请求头数据,则选择默认请求头
                pass
            elif type(headerdict) in (dict,): #若传入的更新的请求头数据为字典格式,则更新到默认请求头
                for key in headerdict: #判断待添加到默认head中的键值对
                    head[key]=headerdict[key] #根据输入更新默认head数据
            else:
                logging.error(u'请确保输入的请求头更新数据格式为字典格式!' )
                raise Exception
            print '服务器接收请求报文的地址为:',request_url
            print '客户端请求xml报文数据为(客户端  --> 服务器):
    ',textpalindata
          
            #发送请求报文到商户前置
            r = requests.post(request_url,data=textpalindata,headers=head)
            print '请求头headers为: ',r.request.headers
            
            #获取请求响应报文数据
            responsedata=r.text
            print "get the status: ",r.status_code
            print '服务器响应报文为(客户端  <-- 服务器): ',responsedata
              
            #返回请求响应报文
            return responsedata
    

      

  • 相关阅读:
    .NET 环境中使用RabbitMQ
    WPF窗口模板——Style样式
    C#获取当前日期时间
    C#解析JSON字符串总结
    c#简单加密和对称加密
    List<T>转换为二维数组
    java后台导出pdf
    C# 创建 读取 更新 XML文件
    python 第三天
    编写登录接口
  • 原文地址:https://www.cnblogs.com/apple2016/p/14250195.html
Copyright © 2011-2022 走看看