http协议

http长连接, 长连接的时候,每次发送数据共用一个socket

 

Get在url中传递数组

https://192.168.91.131/adminapi/logs/sys-export-ids?id[]=10&id[]=11&id[]=12

post传递数组

url中query param可以传递数组, 可以按照如下的拼接形式:&userId=11&userId=12&userId=&userId=

特点:同一个Key值可以出现多次,  Value值可以为空

body中也可以传递数组,内容如下:

groupId=1000&groupName=pujie&headImgUrl=127.0.0.1%2Fhead.png&userId=1&userId=2&userId=3

使用go http post数组

import (	
	"net/http"
	"net/url"
	"io/ioutil"	
	"fmt"	
)
func httpPostForm() {
	users := []string{"1000", "1001","1002"}
    resp, err := http.PostForm("http://127.0.0.1:18000/group/create",
        url.Values{"userId": users , "groupName": {"123"}})
 
    if err != nil {
        // handle error
    } 
    defer resp.Body.Close()
    body, err := ioutil.ReadAll(resp.Body)
    if err != nil {
        // handle error
    } 
    fmt.Println(string(body)) 
}

 

 

dictHeaders = {'User-Agent' : 'Mozilla/5.0 compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0',
               'Connection' : 'Keep-Alive',
              # 'Keep-Alive' : 'timeout=10',
               "AppId":config.PUBSUB_CFG['GetHeader']['AppId'],
               "Subkey": config.PUBSUB_CFG['GetHeader']['Subkey']}


httpconn = None


def HttplibGet(strUrl):
    urlParse = urlparse.urlparse(strUrl)
    strPath = urlParse.path
    strHost = urlParse.hostname
    iPort = urlParse.port
    strPath = strPath + "?" + urlParse.query
    response = {}
    response["status"] = 404
    strRspData = ''
    #strQueryString = urllib.urlencode(listPara) 
    global httpconn
    try:
        if None == httpconn:       
            httpconn = httplib.HTTPConnection(strHost, iPort)
        httpconn.request('GET', strPath, None, dictHeaders)
        response = httpconn.getresponse()
        strRspData = response.read()
    except Exception, e:
        print 'socket error'
        httpconn.close()
        httpconn = None
        
#     if response.status == 200:
#         ret = True
#     httpconn.close()
    return int(response.status), strRspData

 

keepliave

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值