• Uncategorized

About linux : Powershell-PSCredential-implementation-in-Golang-when-making-a-http-requests

Question Detail

In a web request initiated in powershell I am able to authorize with a website which i use this code:

$password = ConvertTo-SecureString "grade" -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist "student", $password
Invoke-WebRequest -Uri 'url to the website' -Credential $cred

Now I want to implement the same thing in go:

tr := &http.Transport{
    TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
    DisableKeepAlives: true,
client := &http.Client{
    Transport: tr,
v := url.Values{}
v.Set("steve", "third")
req, err := http.NewRequest("POST", "the same website as above", strings.NewReader(v.Encode()))
req.SetBasicAuth("steve", "third")

resp, err := client.Do(req)

I can make a post request against other websites like https://ptsv2.com/.

My only question is what is the role of PSCredential and SecureString and how can I reimplement the same functionality in the golang?

  • My deployment environment is linux so I cannot import Powershell
    or C# into my code
  • Go version is 1.17.2
  • The website is local and under development but I don’t have access to the source code

Question Answer

No answer for now.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.