-
-
Save sffej/a2f37a6569f5f600bba8ea865fac27ef to your computer and use it in GitHub Desktop.
Revisions
-
buroz revised this gist
May 15, 2020 . 1 changed file with 13 additions and 6 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -31,27 +31,31 @@ type GetCitiesRequest struct { XMLName xml.Name `xml:"sch:GetCitiesRequest"` } type GetCitiesResponse struct { XMLName xml.Name `xml:"ns3:GetCitiesResponse"` result struct{} `xml:result` cities struct{} `xml:cities` } func SoapCall(service string, request interface{}) string { var root = SoapRoot{} root.X = "http://schemas.xmlsoap.org/soap/envelope/" root.Sch = "http://www.n11.com/ws/schemas" root.Header = SoapHeader{} root.Body = SoapBody{} root.Body.Request = request out, _ := xml.MarshalIndent(&root, " ", " ") body := string(out) client := &http.Client{ Transport: &http.Transport{ TLSClientConfig: &tls.Config{ InsecureSkipVerify: true, }, }, } response, err := client.Post(service, "text/xml", bytes.NewBufferString(body)) if err != nil { fmt.Println(err) @@ -60,6 +64,9 @@ func main() { content, _ := ioutil.ReadAll(response.Body) s := strings.TrimSpace(string(content)) return s } func main() { SoapCall("https://api.n11.com/ws/CityService.wsdl", GetCitiesRequest{}) } -
buroz created this gist
May 15, 2020 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,65 @@ package main import ( "bytes" "crypto/tls" "encoding/xml" "fmt" "io/ioutil" "net/http" "strings" ) type SoapHeader struct { XMLName xml.Name `xml:"x:Header"` } type SoapBody struct { XMLName xml.Name `xml:"x:Body"` Request interface{} } type SoapRoot struct { XMLName xml.Name `xml:"x:Envelope"` X string `xml:"xmlns:x,attr"` Sch string `xml:"xmlns:sch,attr"` Header SoapHeader Body SoapBody } type GetCitiesRequest struct { XMLName xml.Name `xml:"sch:GetCitiesRequest"` } func main() { var root = SoapRoot{} root.X = "http://schemas.xmlsoap.org/soap/envelope/" root.Sch = "http://www.n11.com/ws/schemas" root.Header = SoapHeader{} root.Body = SoapBody{} root.Body.Request = GetCitiesRequest{} out, _ := xml.MarshalIndent(&root, " ", " ") body := string(out) link := "https://api.n11.com/ws/CityService.wsdl" client := &http.Client{ Transport: &http.Transport{ TLSClientConfig: &tls.Config{ InsecureSkipVerify: true, }, }, } response, err := client.Post(link, " text/xml", bytes.NewBufferString(body)) if err != nil { fmt.Println(err) } defer response.Body.Close() content, _ := ioutil.ReadAll(response.Body) s := strings.TrimSpace(string(content)) fmt.Println(s) }