zoukankan      html  css  js  c++  java
  • HTTPResponse.read([amt]):只能read一次

    业务需要:我要写个tanx模拟器,给DSP发竞价请求。

    下面是部分代码:

      def PostDataToDSP(self,url,postdata):
             headers = {
                  'Content-Type':'application/octet-stream',
                  'Connection':'Keep-Alive',
             }
     
             payload = postdata.SerializeToString()
     
             conn = httplib.HTTPConnection(url)
             conn.request(method='POST',url='/bid',body = payload, headers = headers)
             response = conn.getresponse()
     
             print response.status
     
             if 200 == response.status:
                 print response.read()
                 print 'send successfully'
             else:
                 print 'send failed'
    
             conn.close()
             return response.read()

    这个代码是错误的,刚接触互联网行业,一堆不懂。

    老大指点说:只能read一次。

    代码修改后:

      def PostDataToDSP(self,url,postdata):
             headers = {
                  'Content-Type':'application/octet-stream',
                  'Connection':'Keep-Alive',
             }
     
             payload = postdata.SerializeToString()
     
             conn = httplib.HTTPConnection(url)
             conn.request(method='POST',url='/bid',body = payload, headers = headers)
             response = conn.getresponse()
     
             print response.status
     
             if 200 == response.status:
                 res = response.read()
                 print 'send successfully'
             else:
                 print 'send failed'
    
             conn.close()
             return res
  • 相关阅读:
    Sql Server截断日志(转)
    C#/VB.NET语法的比较(转)
    ReportViewer矩阵报表
    逐步学习 iPhone App 开发(1)
    一月二十四日,无家可归
    再见2009
    poj 1376 机器人广搜
    hdu 1004 颜色问题
    hdu 2734 简单地字符串处理
    1116 贪婪的送礼者
  • 原文地址:https://www.cnblogs.com/HpuAcmer/p/4074703.html
Copyright © 2011-2022 走看看