Created
April 4, 2017 16:02
-
-
Save rusco/b989c7b97638b17372f9510f015509b7 to your computer and use it in GitHub Desktop.
Post to .asmx with Golang on Win10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io/ioutil" | |
"net/http" | |
"os" | |
"github.com/Azure/go-ntlmssp" | |
) | |
func main() { | |
url, username, password := "https://someservice/some.asmx/somemethod", "user", "password" | |
client := &http.Client{Transport: ntlmssp.Negotiator{RoundTripper: &http.Transport{}}} | |
req, _ := http.NewRequest("POST", url, nil) | |
req.SetBasicAuth(username, password) | |
req.Header.Set("Content-Length", "0") | |
req.Header.Set("Content-Type", "application/json; charset=utf-8") | |
res, err := client.Do(req) | |
if err != nil { | |
fmt.Println(err) | |
os.Exit(1) | |
} | |
defer res.Body.Close() | |
answerHTML, err := ioutil.ReadAll(res.Body) | |
if err != nil { | |
fmt.Println(err) | |
os.Exit(1) | |
} | |
fmt.Println(string(answerHTML)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment