【问题标题】:Network calling using Dio is not working and returns error code 400使用 Dio 的网络调用不起作用并返回错误代码 400
【发布时间】:2022-06-10 17:54:21
【问题描述】:

我需要调用下面的 api,我从一天开始尝试这样做,尝试了这么多示例和这么多方法,但我没有成功我真的筋疲力尽主机可以访问但每个示例都给出不同的错误

网址:http://192.168.1.67:36211/api/Account/UserLogin

json 是

{
    "AuthToken": {
        "AuthKey": "FJ1189A002023",
        "AuthToken": "",
        "AuthValue": "",
        "LoginTimeStamp": "2022-06-07 10:08:15.316",
        "RequestNumber": 1,
        "UserID": "1"
    },
    "EntityObject": {
        "ClientMAC": "02:00:00:00:00:00",
        "MailID": "kia@gmail.com",
        "PasswordEncrypted": "KIA",
        "SessionIdentifier": "192.168.1.186"
    }
}

这里 AuthToken 对象值是硬编码的。

最后尝试的方法是

void userLogin() async{
    EntityObject eo = EntityObject(mailID: userName,passwordEncrypted: password);
    AuthToken ao = AuthToken();
    WMSCoreMessage wmsCoreMessage = WMSCoreMessage(entityObject: eo,authToken: ao);
    //final data = wmsCoreMessage.toJson();
   
    var url = Apis.login2;
    Response response = await Dio().post(url,
        data: wmsCoreMessage);
    print('response : $response');

}

我做错了什么,谁能指导我如何做到这一点,

【问题讨论】:

    标签: flutter api dio


    【解决方案1】:

    问题可能不在您这边,服务器可能实际上已关闭且无法访问。

    如果您想测试任何主机以查看它是否可以访问并检查到达它所消耗的时间,您可以在终端或命令提示符中运行简单的ping 命令:

    www.google.com 的示例:

    ping google.com
    

    输出:

    Pinging google.com [172.217.171.206] with 32 bytes of data:
    Reply from 172.217.171.206: bytes=32 time=39ms TTL=117
    Reply from 172.217.171.206: bytes=32 time=38ms TTL=117
    Reply from 172.217.171.206: bytes=32 time=39ms TTL=117
    Reply from 172.217.171.206: bytes=32 time=38ms TTL=117
    
    Ping statistics for 172.217.171.206:
        Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
    Approximate round trip times in milli-seconds:
        Minimum = 38ms, Maximum = 39ms, Average = 38ms
    

    或您的 API 的 IP:

    ping 192.168.1.67
    

    输出:

    Pinging 192.168.1.67 with 32 bytes of data:
    Request timed out.
    Request timed out.
    Request timed out.
    Request timed out.
    
    Ping statistics for 192.168.1.67:
        Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),
    

    您可以看到,当我们 ping google.com 时,我们收到了它的重播,但是当我们尝试关闭主机时,我们没有收到任何数据包。

    【讨论】:

    • 嗨,sawaf,这与 ping 问题无关。我能够 ping ip,但我得到 err400,现在在对我的代码进行一些更改后,我得到了这个错误:DioError [DioErrorType.connectTimeout]: Connecting timed out [0ms]
    • 请帮我得到答复
    • 你能分享一下ping操作的输出吗?
    猜你喜欢
    • 2014-05-11
    • 1970-01-01
    • 2016-09-19
    • 1970-01-01
    • 1970-01-01
    • 2019-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多