flutter 我不明白代码中的问题出在哪里

j2qf4p5b  于 2022-12-27  发布在  Flutter
关注(0)|答案(1)|浏览(200)

加载数据失败500我不明白问题到底出在哪里,有人能帮我吗?

我认为有一些问题在我的代码,但我不知道在哪里
'

class UserProvider{ 
    TextEditingController motDePasseController = TextEditingController();    
    TextEditingController identifiantController = TextEditingController(); 
    final _body = '''
    <?xml version="1.0" encoding="utf-8"?>
    <soapenv:Envelope xmlns:soapenv="link" 
    xmlns:ser="http:/link.fr/">
    <soapenv:Header/>
    <soapenv:Body>
    <ser:authentifierUtilisateur>
    </ser:authentifierUtilisateur>
    </soapenv:Body>
    </soapenv:Envelope>'link';
    UserProvider(){} 
    Future<List<UsersModel>> loginUser( ) async{ 
    try{ 
    var response = await http.post(          Uri.parse(''),
    headers: { 'content-type': 'text/xml; charset=utf-8',
    'SOAPAction': '',     
    HttpHeaders.authorizationHeader: '4e1bae794a5a905db6620ab0be1c593c',

     },
     body: utf8.encode(_body),
    );
     if(response.statusCode == 200){  
      identifiantController.clear();
      motDePasseController.clear();
     // Get.off(const HomePage());
      final responseBody = response.body;
      final parseXml = xml.XmlDocument.parse(responseBody).innerText;
      final decodeJson = jsonDecode(parseXml) as List;
      List<UsersModel> data =
        decodeJson.map((e) => UsersModel.fromJson(e)).toList();
        return data;
     } else{  print(response.statusCode.toString());
     throw Exception('Failed load data ${response.statusCode}');
     }
     }catch(error){
     print (error); 
    throw error;}

    }

     }`

我该如何解决这个问题?谢谢

yc0p9oo0

yc0p9oo01#

您应该在_body上使用以下代码:

'''
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="link" 
xmlns:ser="http:/link.fr/">
<soapenv:Header/>
<soapenv:Body>
<ser:authentifierUtilisateur>
</ser:authentifierUtilisateur>
</soapenv:Body>
</soapenv:Envelope>'link';
UserProvider(){} 
Future<List<UsersModel>> loginUser( ) async{ 
try{ 
var response = await http.post(          Uri.parse(''),
headers: { 'content-type': 'text/xml; charset=utf-8',
'SOAPAction': '',     
HttpHeaders.authorizationHeader: '4e1bae794a5a905db6620ab0be1c593c',

 },
 body: utf8.encode(_body),
);
 if(response.statusCode == 200){  
  identifiantController.clear();
  motDePasseController.clear();
 // Get.off(const HomePage());
  final responseBody = response.body;
  final parseXml = xml.XmlDocument.parse(responseBody).innerText;
  final decodeJson = jsonDecode(parseXml) as List;
  List<UsersModel> data =
    decodeJson.map((e) => UsersModel.fromJson(e)).toList();
    return data;
 } else{  print(response.statusCode.toString());
 throw Exception('Failed load data \$response.statusCode');
 }
 }catch(error){
 print (error); 
throw error;}
}'''

相关问题