0

El error que me da es el siguiente. "FormatException (FormatException: Invalid radix-10 number (at character 1) Length." He revisado otras preguntas similares pero la solución no me sirve, no puedo sustituir http, por https y tampoco por Uri.parse porque no me admite el parámetro body que es donde está el xml que lleva los datos de usuario y password. Le he pegado muchas vueltas al cdigo y no hayo la solución, a ver si alguien se le ocurre que me puede estar pasando.

Muchas gracias de antemano.

    import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:jpa/models/models.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:xml/xml.dart' as xml;

import 'package:http/http.dart' as http;

class ClientsService extends ChangeNotifier {
  final String _baseUrl = 'URL SIN HTTP';
  final String _body = ''' 
  <?xml version="1.0" encoding="utf-8"?>
  <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
      <Cliente_Lista xmlns="URL CON HTTP">
        <usuario>USUARIO</usuario>
        <password>CONTRASEÑA</password>
      </Cliente_Lista>
    </soap:Body>
  </soap:Envelope> ''';

  final List<Client> clients = [];
  late Client selectedClient;

  final storage = new FlutterSecureStorage();

  bool isLoading = true;

  ClientsService() {
    this.loadClients();
  }

  Future<List<Client>> loadClients() async {
    this.isLoading = true;
    notifyListeners();

    final url = Uri.http(_baseUrl, '/eNotasCRM_Cliente.asmx');

    final resp = await http.post(
      url,
      headers: {
        "Cache-Control": "private, max-age=0",
        "Content-Type": "text/xml; charset=utf-8",
        "Server": "Microsoft-IIS/7.5",
        "X-AspNet-Version": "4.0.30319",
        "X-Powered-By": "ASP.NET",
        "Content-Length": "Length",
      },
      body: _body,
    );

    print(resp);

    //final Map clientsMap = json.decode(resp.body);
    final responseBody = resp.body;

    final parseXml = xml.XmlDocument.parse(responseBody).innerText;
    final decodeJson = jsonDecode(parseXml);

    decodeJson.forEach((key, value) {
      final tempClient = Client.fromJson(value);
      tempClient.codigo = key;
      this.clients.add(tempClient);
    });

    this.isLoading = false;
    notifyListeners();

    return this.clients;
  }
}
2

0

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

Examina otras preguntas con la etiqueta o formula tu propia pregunta.