Closed kefahB closed 4 years ago
It come from
IOS:
https.ios
Android:
https.android
// IOS
let contentType = opts.headers['Content-Type'].substring(0, 16);
if (opts.headers && contentType === 'application/json') {
manager.requestSerializer = AFJSONRequestSerializer.serializer();
manager.responseSerializer =
AFJSONResponseSerializer.serializerWithReadingOptions(NSJSONReadingOptions.AllowFragments);
}
// Android
// For android I do not testing yet but from this line I think there is no problem
let type = opts.headers && opts.headers['Content-Type'] ? <string>opts.headers['Content-Type'] : 'application/json';
@kefahB Although I have omitted to write 'charset = utf-8', can be my problem (https://github.com/EddyVerbruggen/nativescript-https/issues/59) related to what you have revealed?
Hi @panagulis72 ,
Yes it can be the problem because like you see if you set the utf-8
the data wil not be serialized
by the plugin .. if you want to be sure try to modify the https.ios.js
on the plugin directly and change the code by the flowing :
var contentType = opts.headers['Content-Type'].substring(0, 16);
if (opts.headers && contentType === 'application/json') {
manager.requestSerializer = AFJSONRequestSerializer.serializer();
manager.responseSerializer =
AFJSONResponseSerializer.serializerWithReadingOptions(NSJSONReadingOptions.AllowFragments);
}```
I will do a PR about that and we will se what @EddyVerbruggen say about that
Hi @kefahB , thanks for the quick feedback!
I'm using android so I'm looking at https.android.js
file.
Debugging it, I saw it enters this condition:
if ((['GET', 'HEAD'].indexOf(opts.method) !== -1) || (opts.method === 'DELETE' && !types_1.isDefined(opts.body))) {
request_1[methods[opts.method]]();
}
so it skips the type
in the else
condition (var type = opts.headers['Content-Type'] || 'application/json';) and it doesn't add parameters
I dont now about android yet .. I facing this problem with IOS only .. I think there is no problem with android related with Content-type
because it detect if content-type is set and get it as it :
// Android
// For android I do not testing yet but from this line I think there is no problem
let type = opts.headers && opts.headers['Content-Type'] ? <string>opts.headers['Content-Type'] : 'application/json';
If I set the header application/json
first, and then application/json;charset=utf-8
but is the same on android so I guess it works; the problem is that (trying with both Content-types) the params are not sent with GET Api call
Hi @EddyVerbruggen ,
Just a little report about an issu with this plugin.
When I send the a request with the
content-type
:application/json; charset=utf-8
I receive an empty body on the server side ; The issu come from thecharset=utf-8
.. declaring the content-type without it solve the issu .. but I think is preferable to keep the charset.