http - 未来的颤振问题
问题描述
返回类型“响应”有问题。我真的不知道如何处理这种类型。我必须转换它。我只想显示对屏幕的响应。
有人可以解释这个问题吗?
var username = 'dslf-config';
var password = '53259721';
static String port = "37443";
String url = 'https://192.168.2.1:' + port;
//unused.... String parameter = 'Device.DeviceInfo.ModelName';
var body = """
<?xml version="1.0" encoding= "UTF-8" ?>
<soap-env:Envelope soap-enc="http://schemas.xmlsaop.org/soap/encoding/" xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:cwmp="urn:telekom-de.totr64-2-n">
<soap-env:Body>
<cwmp:GetParameterValues xmlns:cwmp="urn:dslforum-org:cwmp-1-0">
<cwmp:ParameterNames soap-env:arrayType="xsd:string[10]">
<xsd:string>Device.DeviceInfo.ModelName</xsd:string>
</cwmp:ParameterNames>
</cwmp:GetParameterValues>
</soap-env:Body>
</soap-env:Envelope>""";
Future<http.Response> getData2() {
bool trustSelfSigned = true;
Map<String, String> headers = {
"Accept": "*/*",
"Content-Type": "text/xml",
"SOAPAction":
"urn:telekom-de:device:TO_InternetGatewayDevice:2#GetParameterValues"
};
HttpClient httpClient = new HttpClient()
..badCertificateCallback =
((X509Certificate cert, String host, int port) => trustSelfSigned);
httpClient.addCredentials(Uri.parse(url), "theRealm",
new HttpClientDigestCredentials(username, password));
IOClient ioClient = new IOClient(httpClient);
return ioClient.post(Uri.parse(url), headers: headers, body: body);
}
getData3() async {
final response = await getData2();
print(response.body);
print(response.statusCode);
print(response.headers);
}
解决方案
目前还不清楚你的问题是什么。如果您希望您的响应正文显示在您的应用程序中,您可以简单地将其放在一个Text
小部件中,例如Text(response.body)
.
如果是关于 HTTP 响应,那么我建议您阅读一篇关于 HTTP 请求和响应如何工作的文章。Flutter 中的http.Response
类只是解析原始 HTTP 响应并将其呈现给用户。
推荐阅读
- javascript - 在 Contao 版本更新后,用于网站平滑滚动的 Javascript 代码不起作用
- typescript - 在 Ionic 3 中承诺后不返回任何数据
- html - 覆盖表格特定单元格的单元格填充
- typescript - 使用 outputPath 中的函数的 Webpack 文件加载器对目录进行 EISDIR 非法操作
- java - 我们如何在 kotlin 中访问 java 中的 .class 文件?
- javascript - 如何通过 http 从 mongoDB 发送大量文档?
- java - application.properties 与 applicationContext.xml
- ios - UICollectionView flowLayout的原理是什么
- android - 单击图标时,BottomNavigationBarItem 打开相应的页面
- php - 在我的 laravel 项目中,assertStatus(200) 的 PHPUnit 测试失败