1

This code work's on Android device and emulator perfectly. On iOS emulator, doesn't work.

I try change String to lower case, remove spaces, etc, nothing resolve.

import 'package:http/http.dart' show Client;
...
Map<String,String> headers = Map();
headers['device'] = 'appleiphonexʀ';//'Apple-iPhone-Xʀ'//'Apple_iPhone_Xʀ'//'Apple iPhone Xʀ'
...
var response = await client.get(Uri.parse(url), headers: headers);
return await processResponse(response);

Throws Exception:

[VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: FormatException: Invalid HTTP header field value: "appleiphonexʀ"
  _HttpHeaders._validateValue (dart:_http/http_headers.dart:601:9)
  _HttpHeaders._addAll (dart:_http/http_headers.dart:65:18)
  _HttpHeaders.set (dart:_http/http_headers.dart:76:5)
  IOClient.send.<anonymous closure> (package:http/src/io_client.dart:42:27)
  __CompactLinkedCustomHashMap&_HashFieldBase&MapMixin&_LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:367:8)
  IOClient.send (package:http/src/io_client.dart:41:23)
 < asynchronous suspension>
  BaseClient._sendUnstreamed (package:http/src/base_client.dart:169:38)
 < asynchronous suspension>
  BaseClient.post (package:http/src/base_client.dart:54:7)
  NetworkProvider.post (package:PROJECTXX/src/models/resources/network_provider.dart:24:22)
<asynchronous suspension>

Solved: see answer

2 Answers 2

2

The last character in your header is the Unicode code point hex 0280 aka LATIN LETTER SMALL CAPITAL R. According to RFC 2616, HTTP headers must only include characters in ISO-8859-1, unless they are encoded in a MIME format, which might look like =?UTF-8?Q?=E2=9C=B0?=. Could you instead use lower or uppercase ASCII R?

Sign up to request clarification or add additional context in comments.

1 Comment

Thx @Richard Heap, after remove last character works perfectly., the problem wasn´t iOS
2

Follow Richard Heap comment, the problem was the last character, this data came from lib device_info: ^0.4.0+1

final DeviceInfoPlugin deviceInfoPlugin = new DeviceInfoPlugin();
PackageInfo packageInfo = await PackageInfo.fromPlatform();
...
var device = await deviceInfoPlugin.iosInfo.name;//Apple iPhone Xʀ
...
//the solution: remove non ascii chars and substitute for underline        
headers['device'] = device.replaceAll(new RegExp('[^\u0001-\u007F]'),'_');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.