I
I
impressive172021-04-24 22:54:08
go
impressive17, 2021-04-24 22:54:08

How to pass user in header via http.Client.Do() in golang?

I need to repeat the curl request via http.client.Do()
In the curl, I use the -u user:password key.
In golang, via header.Add, I could not repeat this. The request returned an authentication error.
Can you please tell me how to correctly pass user:password to the request?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
uvelichitel, 2021-04-24
@impressive17

*request.SetBasicAuth(user, password)
client.Do(*request)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question