Answer the question
In order to leave comments, you need to log in
How to create a request cookie?
type User struct {
Success bool `json:"success"` // свойство FirstName будет преобразовано в ключ "name"
}
func Authentication(token string,r *http.Request) bool {
client := http.DefaultClient \\как вложить токен в куки при отправке запроса?
response, err := client.Post("https://name.ru/ios/login", "application/x-www-form-urlencoded", strings.NewReader(url.Values{}.Encode()))
if err != nil {
panic(err)
}
defer response.Body.Close()
b, err := ioutil.ReadAll(response.Body)
if err != nil {
panic(err)
}
var user = User{}
err = json.Unmarshal(b,&user)
if err != nil {
panic(err)
}
return user.Success
}
Answer the question
In order to leave comments, you need to log in
import (
"net/http"
"net/http/cookiejar" //из этого пакета
)
...
jar, err := cookiejar.New(options)
if err == nil {
coocies := []http.Coocie{{Name: "token", Value: token}} //здесь собрать
jar.SetCookies(url, coocies) //здесь привязать к Url
}
client := http.DefaultClient //как вложить токен в куки при отправке запроса?
client.Jar = jar //здесь выдать клиенту
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question