gpt4 book ai didi

vb.net - WebService 使用 Visual Basic 发送 SOAP 请求并接收响应

转载 作者:行者123 更新时间:2023-12-02 07:09:56 25 4
gpt4 key购买 nike

我的客户给了我一个 WebService url = https://public-ws-stage.dpd.com/services/LoginService/V2_0 ,他告诉我,如果我发送这个 xml 文本:

enter image description here

但是,如果我使用此代码,这是不对的:

Dim Request As WebRequest
Dim Response As WebResponse
Dim DataStream As Stream
Dim Reader As StreamReader
Dim SoapByte() As Byte
Dim SoapStr As String
Dim pSuccess As Boolean = True

SoapStr = "<?xml version=""1.0"" encoding=""utf-8""?>"
SoapStr = SoapStr & "<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"">"
SoapStr = SoapStr & "<soapenv:Header/>"
SoapStr = SoapStr & "<soapenv:Body>"
SoapStr = SoapStr & "<ns:getAuth> <delisId>id</delisId> <password>pass</password> <messageLanguage>de_DE</messageLanguage> </ns:getAuth>"
SoapStr = SoapStr & "</soapenv:Body>"
SoapStr = SoapStr & "</soapenv:Envelope>"

Try
SoapByte = System.Text.Encoding.UTF8.GetBytes(SoapStr)

Request = WebRequest.Create("https://public-ws-stage.dpd.com/services/LoginService/V2_0/?wsdl")
Request.Headers.Add("SOAPAction", "https://public-ws-stage.dpd.com/services/LoginService/V2_0/getAuth")

Request.ContentType = "text/xml; charset=utf-8"
Request.ContentLength = SoapByte.Length
Request.Method = "POST"

DataStream = Request.GetRequestStream()
DataStream.Write(SoapByte, 0, SoapByte.Length)
DataStream.Close()

Response = Request.GetResponse()
DataStream = Response.GetResponseStream()
Reader = New StreamReader(DataStream)
Dim SD2Request As String = Reader.ReadToEnd()

DataStream.Close()
Reader.Close()
Response.Close()

Catch ex As WebException
MsgBox(ex.ToString())
End Try

不要返回我的客户告诉的内容,我不明白该网址是否不正确,或者我写了错误的代码,请帮助我。

最佳答案

尝试更改不带“?wsdl”的 URL:

Request = WebRequest.Create("https://public-ws-stage.dpd.com/services/LoginService/V2_0/?wsdl")

对此:

Request = WebRequest.Create("https://public-ws-stage.dpd.com/services/LoginService/V2_0/")

关于vb.net - WebService 使用 Visual Basic 发送 SOAP 请求并接收响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32136293/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com