Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DioError [DioErrorType.RESPONSE]: Http status error [401] #668

Closed
1 task done
NeoMindStd opened this issue Feb 3, 2020 · 19 comments
Closed
1 task done

DioError [DioErrorType.RESPONSE]: Http status error [401] #668

NeoMindStd opened this issue Feb 3, 2020 · 19 comments

Comments

@NeoMindStd
Copy link

NeoMindStd commented Feb 3, 2020

New Issue Checklist

  • I have searched for a similar issue in the project and found none

Issue Info

Info Value
Platform Name flutter(android)
Platform Version Flutter 1.12.13+hotfix.7 • channel stable
Dio Version 3.0.8
Android Studio / Xcode Version Android Studio 3.5.3
Repro rate all the time (100%)
Repro with our demo prj NeoMindStd/HoliNoti
Demo project link HoliNoti

Issue Description and Steps

In my flutter apps(holinoti/admin, holinoti/customer)
dio 's get method gives bad response 415

Correctly worked dio with the same code a few months ago(dio: ^3.0.2) and Tested with Postman, GET(http://holinoti.tk:8080/holinoti/facilities/) Header(Content-Type:application/json) is correctly run

code(Client):

try {
    Response facilityResponse = await Dio().get(
    "http://holinoti.tk:8080/holinoti/facilities/",
    options: Options(headers: {"Content-Type":"application/json"}),
  );

  print('Response: ${facilityResponse.data}');

  for(Map facilityJson in facilityResponse.data) {
    facilities.add(Facility.fromJson(facilityJson));
  }
  return facilities;

} catch(e) {
  print(e);
  return [];
}

Also, I tried the options: Options(headers: {"accept" : "application/json","content-type" : "application/json;charset=UTF-8"}), Options(contentTypes":application/json"), and No Options

code(Spring boot Rest API Server):
@RequestMapping(value = "/facilities", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)

log: I/flutter (27156): DioError [DioErrorType.RESPONSE]: Http status error [415]

@NeoMindStd
Copy link
Author

NeoMindStd commented Feb 4, 2020

+) Response: {timestamp: 2020-02-04T11:01:26.352+0000, status: 415, error: Unsupported Media Type, message: Content type '' not supported, path: /holinoti/facilities}
for next options:
Options(headers: {"Content-Type": "application/json"},validateStatus: (_)=>true),
Options(contentType: Headers.jsonContentType, responseType:ResponseType.json,validateStatus: (_)=>true),

and I tried to:

try {
  Dio dio = new Dio(BaseOptions(contentType: Headers.jsonContentType,responseType: ResponseType.json,validateStatus: (_)=>true,));
  Response facilityResponse = await dio.get(
    "http://holinoti.tk:8080/holinoti/facilities"
  );

  print('Response: ${facilityResponse.data}');

but same response.

NeoMindStd added a commit to NeoMindStd/HoliNoti that referenced this issue Feb 4, 2020
 - Changed the automatic import of the Dio library using pubspec.yaml to the manual import the issue # 668 of dio (cfug/dio#668) resolved version

 - See README.md for other version change history
NeoMindStd added a commit to NeoMindStd/HoliNoti that referenced this issue Feb 5, 2020
…ing codes

 - Changed the automatic import of the Dio library using pubspec.yaml to the manual import the issue # 668 of dio (cfug/dio#668) resolved version

 - See README.md for other version change history
NeoMindStd added a commit to NeoMindStd/HoliNoti that referenced this issue Feb 5, 2020
…ing codes

 - Changed the automatic import of the Dio library using pubspec.yaml to the manual import the issue # 668 of dio (cfug/dio#668) resolved version

 - See README.md for other version change history
@stale
Copy link

stale bot commented Mar 5, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, please make sure it is up to date and if so, add a comment that this is still an issue to keep it open. Thank you for your contributions.

@stale stale bot added the stale label Mar 5, 2020
@NeoMindStd
Copy link
Author

this is still an issue to keep it open

@stale stale bot removed the stale label Mar 5, 2020
@Tonigt
Copy link

Tonigt commented Mar 13, 2020

I/flutter (24000): statusCode: 400
I/flutter (24000): headers:
I/flutter (24000): cache-control: no-store, no-cache, max-age=0
I/flutter (24000): date: Fri, 13 Mar 2020 07:57:46 GMT
I/flutter (24000): content-length: 69
I/flutter (24000): x-miniprofiler-ids: ["81a1bdb5-bac9-45bb-adc3-a64e1144e748","f2646561-3e53-465a-a247-4bf753baefce","658f72b8-b3a3-4e70-90af-4b776e1fad1c","e3ee6047-cc61-4dc6-a892-59a084b0a04a","c77ef5bf-eabd-495c-bb4e-bbbc684d5a80","0f0a037f-aafb-4741-b2dd-31a84da85dd9","11ecfa11-4bde-404f-b207-ece3ff61bc97","79fd914d-f7b7-4ba8-87ae-68de181ec9a7","5408373c-1fe3-4c24-995d-974b166ec1bc","2392317d-ea1a-48bd-aa13-ebd940226bb8","65856d6f-a9ff-4905-b732-587669ff87c1","f31d6a36-1ba3-428f-90b3-d29e8c921bf7","ed325450-c1a6-4c85-a73d-f6dc32381cd0","78f63097-d112-4f45-a236-842d55b2ac1b","437e72dc-95f4-46d5-952f-4580e7dd3ee7","880faed4-8454-4fa0-88e2-90ddf057fd6a","afce903b-3efc-47e9-b55c-df9d4ea1bb3b","f88c70c2-c8f8-4343-8b08-9c734b56ecab","21ae319e-3010-436b-9d2b-ac9723a27f16","ee28c314-ac25-47a8-94bc-c2b39feda19b","a0cf173b-9e23-4697-99c5-f6fc9c637c05","da1d353a-8ae8-489b-b3ae-bfa158ba5fdf"]
I/flutter (24000): content-type: application/json; charset=UTF-8
I/flutter (24000): pragma: no-cache
I/flutter (24000): server: Kestrel
I/flutter (24000): Response Text:
I/flutter (24000): {"error":"invalid_grant","error_description":"账号密码错误!"}
I/flutter (24000):
I/flutter (24000):
E/flutter (24000): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: DioError [DioErrorType.RESPONSE]: Http status error [400]
E/flutter (24000): #0 DioMixin._request._errorInterceptorWrapper. (package:dio/src/dio.dart:869:13)
E/flutter (24000):
E/flutter (24000): #1 _rootRunUnary (dart:async/zone.dart:1134:38)
E/flutter (24000): #2 _CustomZone.runUnary (dart:async/zone.dart:1031:19)
E/flutter (24000): #3 _FutureListener.handleError (dart:async/future_impl.dart:157:20)
E/flutter (24000): #4 Future._propagateToListeners.handleError (dart:async/future_impl.dart:692:47)
E/flutter (24000): #5 Future._propagateToListeners (dart:async/future_impl.dart:713:24)
E/flutter (24000): #6 Future._completeError (dart:async/future_impl.dart:532:5)
E/flutter (24000): #7 _SyncCompleter._completeError (dart:async/future_impl.dart:57:12)
E/flutter (24000): #8 _Completer.completeError (dart:async/future_impl.dart:29:5)
E/flutter (24000): #9 Future.any. (dart:async/future.dart:462:45)
E/flutter (24000): #10 _rootRunBinary (dart:async/zone.dart:1146:38)
E/flutter (24000): #11 _CustomZone.runBinary (dart:async/zone.dart:1039:19)
E/flutter (24000): #12 _FutureListener.handleError (dart:async/future_impl.dart:153:20)
E/flutter (24000): #13 Future._propagateToListeners.handleError (dart:async/future_impl.dart:692:47)
E/flutter (24000): #14 Future._propagateToListeners (dart:async/future_impl.dart:713:24)
E/flutter (24000): #15 Future._completeError (dart:async/future_impl.dart:532:5)
E/flutter (24000): #16 _AsyncAwaitCompleter.completeError (dart:async-patch/async_patch.dart:38:15)
E/flutter (24000): #17 DioMixin._dispatchRequest (package:dio/src/dio.dart)
E/flutter (24000):
E/flutter (24000): #18 DioMixin._request._interceptorWrapper... (package:dio/src/dio.dart:849:37)
E/flutter (24000): #19 DioMixin.checkIfNeedEnqueue (package:dio/src/dio.dart:1117:22)
E/flutter (24000): #20 DioMixin._request._interceptorWrapper.. (package:dio/src/dio.dart:846:22)
E/flutter (24000): #21 new Future. (dart:async/future.dart:176:37)
E/flutter (24000): #22 _rootRun (dart:async/zone.dart:1122:38)
E/flutter (24000): #23 _CustomZone.run (dart:async/zone.dart:1023:19)
E/flutter (24000): #24 _CustomZone.runGuarded (dart:async/zone.dart:925:7)
E/flutter (24000): #25 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:965:23)
E/flutter (24000): #26 _rootRun (dart:async/zone.dart:1126:13)
E/flutter (24000): #27 _CustomZone.run (dart:async/zone.dart:1023:19)
E/flutter (24000): #28 _CustomZone.bindCallback. (dart:async/zone.dart:949:23)
E/flutter (24000): #29 Timer._createTimer. (dart:async-patch/timer_patch.dart:23:15)
E/flutter (24000): #30 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:384:19)
E/flutter (24000): #31 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:418:5)
E/flutter (24000): #32 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:174:12)

@Maadhav
Copy link

Maadhav commented Mar 22, 2020

@Tonigt I am also facing the same issue. Did you solve it?

@NeoMindStd
Copy link
Author

@Tonigt I am also facing the same issue. Did you solve it?

You can use it

@stale
Copy link

stale bot commented Apr 26, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, please make sure it is up to date and if so, add a comment that this is still an issue to keep it open. Thank you for your contributions.

@stale stale bot added the stale label Apr 26, 2020
@stale stale bot closed this as completed May 3, 2020
@lakhwinderdebut2014
Copy link

same here

@Maadhav
Copy link

Maadhav commented May 27, 2020 via email

@pmrajani
Copy link

Why dio throw error in release mode for iOS?
ios debug and android release/debug build works fine.

using : dio: ^3.0.10

ERROR: DioError [DioErrorType.RESPONSE]: Http status error [400] \nSTACK: #0 DioMixin._dispatchRequest (package:dio/src/dio.dart:966)\n\n#1 DioMixin._request._interceptorWrapper.... (package:dio/src/dio.dart)\n

@supermebing
Copy link

supermebing commented Sep 15, 2020

using : dio: ^3.0.10
#0 DioMixin._request._errorInterceptorWrapper. . .
package:dio/src/dio.dart:871
#1 _rootRunUnary (dart:async/zone.dart:1198:47)

#2 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
#3 _FutureListener.handleValue (dart:async/future_impl.dart:143:18)
#4 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
#5 Future._propagateToListeners (dart:async/future_impl.dart:725:32)
#6 Future._completeWithValue (dart:async/future_impl.dart:529:5)
#7 Future._asyncCompleteWithValue. (dart:async/future_impl.dart:567:7)
#8 _rootRun (dart:async/zone.dart:1190:13)
#9 _CustomZone.run (dart:async/zone.dart:1093:19)
#10 _CustomZone.runGuarded (dart:async/zone.dart:997:7)
#11 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:1<…>
flutter: common_utils e end:null

@AbdullahAlAsad
Copy link

AbdullahAlAsad commented Oct 17, 2020

Is dio get broken now ?
tried with 3.0.9 and 3.0.10
for both of them when I am trying from android and ios app I am getting 400 and it also returning the complete response. This is very strange.
I am getting 400 for this specific request only. it works as expected in swagger and Postman and also in Flutter Web where I used the same dio 3.0.9

I/flutter ( 2266): uri: https://www.climpio.com/api/v1/product/search/?terms=n95&offset=0
I/flutter ( 2266): method: GET
I/flutter ( 2266): responseType: ResponseType.json
I/flutter ( 2266): followRedirects: true
I/flutter ( 2266): connectTimeout: 100000
I/flutter ( 2266): receiveTimeout: 100000
I/flutter ( 2266): extra: {}
I/flutter ( 2266): headers:
I/flutter ( 2266): content-type: application/json; charset=utf-8
I/flutter ( 2266): Authorization:
I/flutter ( 2266): data:
I/flutter ( 2266): null
I/flutter ( 2266):
I/flutter ( 2266): *** DioError ***:
I/flutter ( 2266): uri: https://www.mydomain.com/api/v1/product/search/?terms=n95&offset=0
I/flutter ( 2266): DioError [DioErrorType.RESPONSE]: Http status error [400]
I/flutter ( 2266): uri: https://www.mydomain.com/api/v1/product/search/?terms=n95&offset=0
I/flutter ( 2266): statusCode: 400
I/flutter ( 2266): headers:
I/flutter ( 2266): connection: keep-alive
I/flutter ( 2266): access-control-allow-credentials: true
I/flutter ( 2266): access-control-allow-headers: Origin,Content-Type,Accept,Authorization
I/flutter ( 2266): date: Sat, 17 Oct 2020 05:13:37 GMT
I/flutter ( 2266): content-encoding: gzip
I/flutter ( 2266): access-control-allow-methods: GET, POST, PATCH, OPTIONS, PUT, DELETE
I/flutter ( 2266): content-length: 0
I/flutter ( 2266): access-control-expose-headers: Date
I/flutter ( 2266): access-control-max-age: 86400
I/flutter ( 2266): content-type: text/plain
I/flutter ( 2266): server: nginx
I/flutter ( 2266): Response Text:
I/flutter ( 2266): [{"product_id": "d2e6223b-b115-40a6-b10b-df2b4669c8fb", "created_timestamp": 1602760222, "updated_timestamp": 1602760222, "viewed": 2, "clicked": 0, "merchant_product_id": "B000GUP7UC", "brand": "3M", "manufacturer": "3m", "i8n_code": "en-US", "title": "3M 1860 Medical Mask N95, 20 Count", "description": "This is a demo product so detailed information is only available for users with access to demo content. To see this content, please create an account and ask support@climp.io to have demo content enabled for your account.", "features": "This is a demo product so detailed information is only available for users with access to demo content. To see this content, please create an account and ask support@climp.io to have demo content enabled for your account.", "number_items": -1, "item_width_mm": 127, "item_height_mm": 127, "item_weight_gram": 272, "publisher": "3m", "studio": "3m", "number_pages": -1, "gtins": ["707387419424", "0707387419424"], "image_urls": ["https://images-na.ssl-images-amazon.com/images/I/4
I/flutter ( 2266):
I/chatty ( 2266): uid=10101(com.mydomain) 1.ui identical 1 line
I/flutter ( 2266):
I/flutter ( 2266): Error cought by interceptor 400
I/flutter ( 2266): error Description --------- Received invalid status code: 400

@NeoMindStd
Copy link
Author

I recommend http and http_auth to you. Maybe, It's gonna work.
@godslave05

@RaoSaqib7860
Copy link

i am handle this error in this way
Options(
headers: {'Authorization': 'Bearer $token'},
followRedirects: false,
validateStatus: (status) {
return status <= 500;
}
)

@farooq-112
Copy link

i am also facing the same issue it worked on firefox not on chrome in windows
DioError [DioErrorType.response]: Http status error [401]
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 906:28 get current
packages/dio/src/dio_mixin.dart 819:20 assureDioError
packages/dio/src/dio_mixin.dart 678:13 _dispatchRequest
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1612:54 runUnary
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 152:18 handleValue
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 704:44 handleValueCallback
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 733:13 _propagateToListeners
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 539:5 [_completeWithValue]
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 577:7 callback
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/schedule_microtask.dart 40:11 _microtaskLoop
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/schedule_microtask.dart 49:5 _startMicrotaskLoop
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 166:15

amondnet added a commit to dietfriends/balance_http that referenced this issue Jun 9, 2021
@RakaAlrian
Copy link

@Tonigt I am also facing the same issue. Did you solve it?

You can use it

link not found, still having similar issue with header WWW-Authenticate: Bearer realm="service" error="invalid_token" error_description="The access token is invalid or has expired". any suggestion please?

@adityagandhi007
Copy link

Exception has occurred.
DioError (DioError [DioErrorType.response]: Http status error [401]
#0 DioMixin.assureDioError (package:dio/src/dio_mixin.dart:819:20)
#1 DioMixin._dispatchRequest (package:dio/src/dio_mixin.dart:678:13)

#2 DioMixin.fetch.. (package:dio/src/dio_mixin.dart:586:9)

)

help me

@Maadhav
Copy link

Maadhav commented Jun 20, 2022

@adityagandhi007 The error 401 means that the HTTP request you send does not have the correct authorization. Have you tried the HTTP request with tools like Postman or curl ?

@adityagandhi007
Copy link

@adityagandhi007 The error 401 means that the HTTP request you send does not have the correct authorization. Have you tried the HTTP request with tools like Postman or curl ?

Oh thanks men

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests