Skip to content

Commit

Permalink
fix #72
Browse files Browse the repository at this point in the history
  • Loading branch information
duwen committed Sep 21, 2018
1 parent a7dd68e commit d4759a9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 11 additions & 6 deletions lib/src/dio.dart
@@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'cancel_token.dart';
import 'form_data.dart';
Expand Down Expand Up @@ -247,7 +248,7 @@ class Dio {
}
}, onDone: () {
raf.closeSync();
response.headers=response.data.headers;
response.headers = response.data.headers;
completer.complete(response);
},
onError: (e) {
Expand Down Expand Up @@ -479,17 +480,18 @@ class Dio {

_transformData(Options options, HttpClientRequest request) async {
var data = options.data;
List<int> bytes;
if (data != null) {
if (["POST", "PUT", "PATCH"].contains(options.method)) {
// Handle the FormData
if (data is FormData) {
request.headers.set(HttpHeaders.CONTENT_TYPE,
'multipart/form-data; boundary=${data.boundary.substring(2)}');
List<int> content = data.bytes();
bytes = data.bytes();
//Must set the content-length
request.contentLength = content.length;
request.contentLength = bytes.length;
_setHeaders(options, request);
request.add(content);
request.add(bytes);
return;
}
}
Expand All @@ -502,10 +504,13 @@ class Dio {
// Set the headers, must before `request.write`
_setHeaders(options, request);

// Convert to utf8
bytes = utf8.encode(_data);

// Set Content-Length
request.headers.set(HttpHeaders.CONTENT_LENGTH, _data.length);
request.headers.set(HttpHeaders.CONTENT_LENGTH, bytes.length);

request.write(_data);
request.add(bytes);
} else {
_setHeaders(options, request);
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
@@ -1,6 +1,6 @@
name: dio
description: A powerful Http client for Dart, which supports Interceptors, FormData, Request Cancellation, File Downloading, Timeout etc.
version: 1.0.5
version: 1.0.6
homepage: https://github.com/flutterchina/dio
author: wendux <824783146@qq.com>

Expand Down

0 comments on commit d4759a9

Please sign in to comment.