Skip to content

Commit

Permalink
fix wendux#67
Browse files Browse the repository at this point in the history
  • Loading branch information
duwen committed May 21, 2018
1 parent 292f1cb commit 5c7a4f2
Show file tree
Hide file tree
Showing 16 changed files with 57 additions and 33 deletions.
1 change: 0 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
node_modules/
build.js
package-lock.json
README.md
/demon
.idea/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ The parameter of all is an array of `promise`, `then` will be called only when
By default, fly serializes JavaScript objects to `JSON`. To send data in the `application/x-www-form-urlencoded` format instead, you can use one of the following options.
### By specify request header
### By specifying `content-type` request header
When you specify `content-type` value as "application/x-www-form-urlencoded", fly will encode the request data automatically, for example:
Expand Down
26 changes: 13 additions & 13 deletions demon/nodeTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ fly.config.baseURL = "http://localhost/ds"
// ]
// }

// var formData={
// name:"xxx",
// file: fs.createReadStream('./v.png'),
// }
// fly.upload("http://localhost/ds/test", formData)
// .then(d => {
// log(d)
// }).catch(log)
var formData = {
name: "haha",
file: fs.createReadStream('./v.png'),
}
fly.upload("http://localhost/ds/test", formData, {proxy: "http://localhost:8888"})
.then(d => {
log(d.data)
}).catch(log)


//fly.download("http://localhost:8089/static/v.png","./vxx.png");
Expand All @@ -53,8 +53,8 @@ fly.config.baseURL = "http://localhost/ds"

//
//post请求
fly.post("http://localhost/ds/test", {xx: "xxx", aa: {bb: 5}}).then(d => {
console.log("post请求成功", d)
}).catch((e) => {
log(`post请求失败,错误码:${e.status}, 错误信息:${e.message}`);
})
// fly.post("http://localhost/ds/test", {xx: "xxx", aa: {bb: 5}}).then(d => {
// console.log("post请求成功", d)
// }).catch((e) => {
// log(`post请求失败,错误码:${e.status}, 错误信息:${e.message}`);
// })
7 changes: 5 additions & 2 deletions dist/fly.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,15 +315,18 @@ var Fly = function () {
}

if (!isGet) {
// default content type
var _contentType = "application/x-www-form-urlencoded";
// If the request data is json object, transforming it to json string,
// and set request content-type to "json". In browser, the data will
// be sent as RequestBody instead of FormData
if (options.headers[contentType].toLowerCase() === "application/x-www-form-urlencoded") {
if (utils.trim((options.headers[contentType] || "").toLowerCase()) === _contentType) {
data = utils.formatParams(data);
} else if (!utils.isFormData(data) && ["object", "array"].indexOf(utils.type(data)) !== -1) {
options.headers[contentType] = 'application/json;charset=utf-8';
_contentType = 'application/json;charset=utf-8';
data = JSON.stringify(data);
}
options.headers[contentType] = _contentType;
}

for (var k in options.headers) {
Expand Down
2 changes: 1 addition & 1 deletion dist/fly.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions dist/npm/fly.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,15 +325,18 @@ var Fly = function () {
}

if (!isGet) {
// default content type
var _contentType = "application/x-www-form-urlencoded";
// If the request data is json object, transforming it to json string,
// and set request content-type to "json". In browser, the data will
// be sent as RequestBody instead of FormData
if (options.headers[contentType].toLowerCase() === "application/x-www-form-urlencoded") {
if (utils.trim((options.headers[contentType] || "").toLowerCase()) === _contentType) {
data = utils.formatParams(data);
} else if (!utils.isFormData(data) && ["object", "array"].indexOf(utils.type(data)) !== -1) {
options.headers[contentType] = 'application/json;charset=utf-8';
_contentType = 'application/json;charset=utf-8';
data = JSON.stringify(data);
}
options.headers[contentType] = _contentType;
}

for (var k in options.headers) {
Expand Down
7 changes: 5 additions & 2 deletions dist/npm/hap.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,15 +622,18 @@
}

if (!isGet) {
// default content type
var _contentType = "application/x-www-form-urlencoded";
// If the request data is json object, transforming it to json string,
// and set request content-type to "json". In browser, the data will
// be sent as RequestBody instead of FormData
if (options.headers[contentType].toLowerCase() === "application/x-www-form-urlencoded") {
if (utils.trim((options.headers[contentType] || "").toLowerCase()) === _contentType) {
data = utils.formatParams(data);
} else if (!utils.isFormData(data) && ["object", "array"].indexOf(utils.type(data)) !== -1) {
options.headers[contentType] = 'application/json;charset=utf-8';
_contentType = 'application/json;charset=utf-8';
data = JSON.stringify(data);
}
options.headers[contentType] = _contentType;
}

for (var k in options.headers) {
Expand Down
7 changes: 5 additions & 2 deletions dist/npm/weex.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,15 +622,18 @@
}

if (!isGet) {
// default content type
var _contentType = "application/x-www-form-urlencoded";
// If the request data is json object, transforming it to json string,
// and set request content-type to "json". In browser, the data will
// be sent as RequestBody instead of FormData
if (options.headers[contentType].toLowerCase() === "application/x-www-form-urlencoded") {
if (utils.trim((options.headers[contentType] || "").toLowerCase()) === _contentType) {
data = utils.formatParams(data);
} else if (!utils.isFormData(data) && ["object", "array"].indexOf(utils.type(data)) !== -1) {
options.headers[contentType] = 'application/json;charset=utf-8';
_contentType = 'application/json;charset=utf-8';
data = JSON.stringify(data);
}
options.headers[contentType] = _contentType;
}

for (var k in options.headers) {
Expand Down
7 changes: 5 additions & 2 deletions dist/npm/wx.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,15 +529,18 @@ var Fly = function () {
}

if (!isGet) {
// default content type
var _contentType = "application/x-www-form-urlencoded";
// If the request data is json object, transforming it to json string,
// and set request content-type to "json". In browser, the data will
// be sent as RequestBody instead of FormData
if (options.headers[contentType].toLowerCase() === "application/x-www-form-urlencoded") {
if (utils.trim((options.headers[contentType] || "").toLowerCase()) === _contentType) {
data = utils.formatParams(data);
} else if (!utils.isFormData(data) && ["object", "array"].indexOf(utils.type(data)) !== -1) {
options.headers[contentType] = 'application/json;charset=utf-8';
_contentType = 'application/json;charset=utf-8';
data = JSON.stringify(data);
}
options.headers[contentType] = _contentType;
}

for (var k in options.headers) {
Expand Down
Loading

0 comments on commit 5c7a4f2

Please sign in to comment.