大佬教程收集整理的这篇文章主要介绍了SOAP--------Golang对接WebService服务实战,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
POST /WSShakespeare.asmx http/1.1 Host: www.xmlme.com Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "http://xmlme.com/Webservices/GetSpeech" <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLscheR_594_11845@a-instance" xmlns:xsd="http://www.w3.org/2001/XMLscheR_594_11845@a" xmlns:soap="http://scheR_594_11845@as.xmlsoap.org/soap/envelope/"> <soap:Body> <GetSpeech xmlns="http://xmlme.com/Webservices"> <request>String</request> </GetSpeech> </soap:Body> </soap:Envelope>
POST /WSShakespeare.asmx http/1.1 Host: www.xmlme.com Content-Type: application/soap+xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLscheR_594_11845@a-instance" xmlns:xsd="http://www.w3.org/2001/XMLscheR_594_11845@a" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> <soap12:Body> <GetSpeech xmlns="http://xmlme.com/Webservices"> <request>String</request> </GetSpeech> </soap12:Body> </soap12:Envelope>
package main import ( "net/http" "Strings" "io/IoUtil" "fmt" ) func main() { Soap11("https://lisea.cn/test") Soap12("https://lisea.cn/test") } func Soap11(url String) { reqBody := `<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLscheR_594_11845@a-instance" xmlns:xsd="http://www.w3.org/2001/XMLscheR_594_11845@a" xmlns:soap="http://scheR_594_11845@as.xmlsoap.org/soap/envelope/"> <soap:Body> <GetSpeech xmlns="http://xmlme.com/Webservices"> <request>String</request> </GetSpeech> </soap:Body> </soap:Envelope>` res,err := http.Post(url,"text/xml; charset=UTF-8",Strings.NewReader(reqBody)) if nil != err { fmt.Println("http post err:",err) return } defer res.body.Close() // return status if http.StatusOk != res.StatusCode { fmt.Println("Webservice soap1.1 request fail,status: %s\n",res.StatusCodE) return } data,err := IoUtil.ReadAll(res.body) if nil != err { fmt.Println("IoUtil ReadAll err:",err) return } fmt.Println("webservice soap1.1 response: ",String(data)) } // soap1.2例子 func Soap12(url String) { reqBody := `<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLscheR_594_11845@a-instance" xmlns:xsd="http://www.w3.org/2001/XMLscheR_594_11845@a" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> <soap12:Body> <GetSpeech xmlns="http://xmlme.com/Webservices"> <request>String</request> </GetSpeech> </soap12:Body> </soap12:Envelope>` res,"application/soap+xml; charset=utf-8",err) return } defer res.body.Close() // return status if http.StatusOk != res.StatusCode { fmt.Println("Webservice soap1.2 request fail,err) return } fmt.Println("webservice soap1.2 response: ",String(data)) }
以上是大佬教程为你收集整理的SOAP--------Golang对接WebService服务实战全部内容,希望文章能够帮你解决SOAP--------Golang对接WebService服务实战所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。