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