Skip to content

Instantly share code, notes, and snippets.

@sffej
Forked from buroz/main.go
Created September 19, 2024 22:55
Show Gist options
  • Select an option

  • Save sffej/a2f37a6569f5f600bba8ea865fac27ef to your computer and use it in GitHub Desktop.

Select an option

Save sffej/a2f37a6569f5f600bba8ea865fac27ef to your computer and use it in GitHub Desktop.

Revisions

  1. @buroz buroz revised this gist May 15, 2020. 1 changed file with 13 additions and 6 deletions.
    19 changes: 13 additions & 6 deletions main.go
    Original file line number Diff line number Diff line change
    @@ -31,27 +31,31 @@ type GetCitiesRequest struct {
    XMLName xml.Name `xml:"sch:GetCitiesRequest"`
    }

    func main() {
    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 = GetCitiesRequest{}
    root.Body.Request = request

    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))
    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
    }

    fmt.Println(s)
    func main() {
    SoapCall("https://api.n11.com/ws/CityService.wsdl", GetCitiesRequest{})
    }
  2. @buroz buroz created this gist May 15, 2020.
    65 changes: 65 additions & 0 deletions main.go
    Original 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)
    }