我需要使用 Flutter 向 .NET Webservice (WSDL) 发出 SOAP 请求。
该网络服务有一个基本的身份验证(用户、密码)和一些带有预定义信封的服务。
所以我尝试创建一个 SOAP 信封:
String requestBody = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tot=\"http://www.totvs.com/\"> <soapenv:Header/> <soapenv:Body> <tot:RealizarConsultaSQL> <!--Optional:--> <tot:codSentenca>ETHOS.TESTE</tot:codSentenca> <!--Optional:--> <tot:codColigada>0</tot:codColigada> <!--Optional:--> <tot:codSistema>F</tot:codSistema> <!--Optional:--> <tot:parameters></tot:parameters> </tot:RealizarConsultaSQL> </soapenv:Body></soapenv:Envelope>";
Run Code Online (Sandbox Code Playgroud)
此信封有效。第二步是建立 http 连接:
http.Response response = await http.post(
request,
headers: {
"Accept-Encoding": "gzip,deflate",
"Content-Length": utf8.encode(requestBody).length.toString(),
"Content-Type": "text/xmlc",
"SOAPAction": "http://www.totvs.com/IwsConsultaSQL/RealizarConsultaSQL",
"Authorization": "Basic bWVzdHJlOnRvdHZz",
"Host": "totvs.brazilsouth.cloudapp.azure.com:8051",
"Connection": "Keep-Alive",
"User-Agent": "Apache-HttpClient/4.1.1 (java 1.5)"
},
body: utf8.encode(requestBody),
encoding: Encoding.getByName("UTF-8")).then((onValue)
{
print("Response status: ${onValue.statusCode}");
print("Response body: ${onValue.body}");
});
Run Code Online (Sandbox Code Playgroud)
此时我刚刚收到 411 代码:
<hr><p>HTTP Error …Run Code Online (Sandbox Code Playgroud)