Xml 颤振/飞镖中的SOAP请求
我需要使用flatter向.NETWebService(WSDL)发出SOAP请求 此Web服务具有基本身份验证(用户、密码)和一些带有预定义信封的服务 所以我尝试创建一个SOAP信封:Xml 颤振/飞镖中的SOAP请求,xml,soap,dart,wsdl,flutter,Xml,Soap,Dart,Wsdl,Flutter,我需要使用flatter向.NETWebService(WSDL)发出SOAP请求 此Web服务具有基本身份验证(用户、密码)和一些带有预定义信封的服务 所以我尝试创建一个SOAP信封: String requestBody = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tot=\"http://www.totvs.com/\"> <soapenv
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>";
此时,我只收到411个代码:
<hr><p>HTTP Error 411. The request must be chunked or have a content length.</p>
HTTP错误411。请求必须分块或具有内容长度
因此,我有两大疑问:
我是Dart/FLATTER方面的新手您设置的标题太多了,因为大多数标题都是由客户端设置的,尤其是内容长度和编码 您的基本身份验证标头看起来正常 不要将等待和随后混用-使用其中一种 您可以将代码简化为:
import 'dart:convert';
import 'package:http/http.dart' as http;
main() async {
String soap = '''<?xml version="1.0"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:tot="http://www.totvs.com/">
<soapenv:Header/>
<soapenv:Body>
<tot:RealizarConsultaSQL>
<tot:codSentenca>ETHOS.TESTE</tot:codSentenca>
<tot:codColigada>0</tot:codColigada>
<tot:codSistema>F</tot:codSistema>
<tot:parameters></tot:parameters>
</tot:RealizarConsultaSQL>
</soapenv:Body>
</soapenv:Envelope>''';
http.Response response = await http.post(
'http://totvs.brazilsouth.cloudapp.azure.com:8051/wherever',
headers: {
'content-type': 'text/xmlc',
'authorization': 'bWVzdHJlOnRvdHZz',
'SOAPAction': 'http://www.totvs.com/IwsConsultaSQL/RealizarConsultaSQL',
},
body: utf8.encode(soap),
);
print(response.statusCode);
}
导入'dart:convert';
将“package:http/http.dart”导入为http;
main()异步{
字符串soap=''
精神病
0
F
''';
http.Response-Response=等待http.post(
'http://totvs.brazilsouth.cloudapp.azure.com:8051/wherever',
标题:{
“内容类型”:“text/xmlc”,
“授权”:“bWVzdHJlOnRvdHZz”,
“SOAPAction”:http://www.totvs.com/IwsConsultaSQL/RealizarConsultaSQL',
},
正文:utf8.编码(soap),
);
打印(响应状态码);
}
请注意,Darthttp
会将所有头名称都小写(RFC允许),但这会混淆某些服务器
使用邮递员尝试您的请求。如果你能让它在那里工作,请编辑显示良好邮递员请求(或其他语言)的问题。在测试中花费了大量时间后,我通过使用以下标题获得了成功:
"SOAPAction": "http://www.totvs.com/IwsConsultaSQL/RealizarConsultaSQL",
"Content-Type": "text/xml;charset=UTF-8",
"Authorization": "Basic bWVzdHJlOnRvdHZz",
"cache-control": "no-cache"
内容长度是自动发送的,因此,工作代码如下:
http.Response response = await http.post(
request,
headers: {
"SOAPAction": "http://www.totvs.com/IwsConsultaSQL/RealizarConsultaSQL",
"Content-Type": "text/xml;charset=UTF-8",
"Authorization": "Basic bWVzdHJlOnRvdHZz",
"cache-control": "no-cache"
},
body: utf8.encode(requestBody),
encoding: Encoding.getByName("UTF-8")
).then((onValue)
{
print("Response status: ${onValue.statusCode}");
print("Response body: ${onValue.body}");
});
谢谢大家的帮助,我通过邮递员代码得到了解决方案,正如之前建议的那样,谢谢。你能通过wireshark或Charles或其他工具嗅出http呼叫吗?也许“内容长度”已经由http.post计算出来了?试着看看你的数据在服务器上是什么样子的,我从服务器上得到了相同的答案。HTTP错误411。请求必须分块或具有内容长度。所以我还是要找出原因。。。有什么线索吗?你能分享一下
8051/任何东西的实际价值吗?你有关于如何使用dart消费soap的详细例子吗?谢谢
http.Response response = await http.post(
request,
headers: {
"SOAPAction": "http://www.totvs.com/IwsConsultaSQL/RealizarConsultaSQL",
"Content-Type": "text/xml;charset=UTF-8",
"Authorization": "Basic bWVzdHJlOnRvdHZz",
"cache-control": "no-cache"
},
body: utf8.encode(requestBody),
encoding: Encoding.getByName("UTF-8")
).then((onValue)
{
print("Response status: ${onValue.statusCode}");
print("Response body: ${onValue.body}");
});