小编Tua*_*inh的帖子

从PHP cURL响应中获取标头

我是PHP的新手.我发送php curl POST请求后尝试从响应中获取Header.客户端将请求发送到服务器,服务器使用Header发回响应.这是我发送POST请求的方式.

   $client = curl_init($url);  
   curl_setopt($client, CURLOPT_CUSTOMREQUEST, "POST");
   curl_setopt($client, CURLOPT_POSTFIELDS, $data_string);
   curl_setopt($client, CURLOPT_HEADER, 1);
   $response = curl_exec($client);
   var_dump($response);
Run Code Online (Sandbox Code Playgroud)

这是我从浏览器获得的服务器的头响应

HTTP/1.1 200 OK 
Date: Wed, 01 Feb 2017 11:40:59 GMT 
Authorization: eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1c2Vycy9CYW9CaW5oMTEwMiIsIm5hbWUiOiJhZG1pbiIsInBhc3N3b3JkIjoiMTIzNCJ9.kIGghbKQtMowjUZ6g62KirdfDUA_HtmW-wjqc3ROXjc Content-Type: text/html;charset=utf-8 Transfer-Encoding: chunked Server: Jetty(9.3.6.v20151106) 
Run Code Online (Sandbox Code Playgroud)

如何从标题中提取授权部分?我需要将它存储在cookie中

php curl header response

14
推荐指数
1
解决办法
5万
查看次数

混合两个列表python

我试图创建一个函数来混合python中的两个列表,或者我更确切地说将list2的元素放入list1.要求在输出列表中,接下来彼此不超过两个元素具有相同的值

例如:

list1 = [1,1,1,1,1]
list2 = [2,2,2,2,2]
output = [1,1,2,1,2,2,1,2,1,2]
Run Code Online (Sandbox Code Playgroud)

错误的输出示例:

# There are more than two '1' standing next two each other
output = [1,1,1,2,2,1,2,1,2,2]
Run Code Online (Sandbox Code Playgroud)

这是我的解决方案:

def guyGenerator(toughGuy,softGuy):
    i = 0
    while len(softGuy) > 0:
        temp = softGuy[:1]
        while i < len(toughGuy) - 1:
            if toughGuy[i] == toughGuy[i + 1] == 2:
                toughGuy.insert(random.randint(i, i + 1), temp[0])
            i = i + 1
        softGuy = softGuy[1:]
    return toughGuy
Run Code Online (Sandbox Code Playgroud)

问题是输出的输出中有两个以上相同的元素,它们彼此相邻,或者输出列表的长度比两个列表的组合长度长

例如我的一个输出

[2, 1, 1, 2, 1, 1, 1, 2, 1, …
Run Code Online (Sandbox Code Playgroud)

python list

8
推荐指数
1
解决办法
717
查看次数

标签 统计

curl ×1

header ×1

list ×1

php ×1

python ×1

response ×1