You don't need to build and encode the Authorization header yourself - you can use Request.SetBasicAuth <https://golang.org/pkg/net/http/#Request.SetBasicAuth>. Building it yourself is fine too, if you do it right - google "go http authorization basic" for some examples.
Your code has a lot of other problems: - you shouldn't put semicolons at the ends of lines - there is no ContentType member in the Request structure - this is a header. It's normally passed as an argument to Post <https://golang.org/pkg/net/http/#Post>. See the code for client.Post <https://golang.org/src/net/http/client.go?s=27914:28004#L829> to see how to do it by hand - similarly, the request method is implied by those functions, or passed as an argument to NewRequest <https://golang.org/pkg/net/http/#NewRequest>. - you seem to be overriding the Host from the url with a different one On Thursday, 17 June 2021 at 17:19:45 UTC+1 Asim Shahzad wrote: > Please anyone guide me that how to consume API using Golang with user name > and password? > > This is the API address > > > https://emea.universal-api.pp.travelport.com/B2BGateway/connect/uAPI/ > AirService > > if have to pass the following with request > > request.Headers.Add("Authorization", "Basic " + > Convert.ToBase64String(Encoding.ASCII.GetBytes("username" + ":" + > "password"))); > > > request.ContentType = "text/xml; encoding='utf-8'"; > > > request.Method = "Post"; > > > request.Headers.Add("SOAPAction", ""); > > > request.Host = "twsprofiler.travelport.com"; > > > > I shall be very thankful to him. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/9bec743a-2f15-4025-a6f1-ba6f8ee3dffdn%40googlegroups.com.