如果我通过document.cookie在浏览器中输入来获取 cookie ,有什么方法可以解析原始字符串并将其保存为http.Cookie吗?
2 回答
红糖糍粑
TA贡献1815条经验 获得超6个赞
package main
import (
"bufio"
"fmt"
"net/http"
"strings"
)
func main() {
rawCookies := "cookie1=value1;cookie2=value2"
rawRequest := fmt.Sprintf("GET / HTTP/1.0\r\nCookie: %s\r\n\r\n", rawCookies)
req, err := http.ReadRequest(bufio.NewReader(strings.NewReader(rawRequest)))
if err == nil {
cookies := req.Cookies()
fmt.Println(cookies)
}
}
- 2 回答
- 0 关注
- 198 浏览
添加回答
举报
0/150
提交
取消