0

I have this very strange problem. I have a very long string as a token for an app. When i`m doing the http post request, the string changes.

From the ending of "Vow== 256220" it is changing to "Vow: = 256220" and i do not understand why.

Here is the code if helps:

var request = $http({
    method: "post",
    url: urlWS,
    data: {token: token},0

    headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
});
request.success(function (data) {
    alert(data);
});

2 Answers 2

1

Following code working for me.

 $http({
        method: "post",
        url: urlWS,
        data: 'token='+encodeURIComponent("Vow== 256220"),
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
    });
    request.success(function (data) {
        alert(data);
    });

May be above solution solve your problem.

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

Comments

0

You will have to configure $httpProvider in your main module config function. This is been done with transformRequest method by firstly adding the default header you have added and then transforming the request.

Add the following code to you main config function module:

$httpProvider.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
// post headers
$httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
$httpProvider.defaults.transformRequest = [function(data) {
    return angular.isObject(data) && String(data) !== '[object File]' ? $.param(data) : data;
}];

I hope it helps ;)

1 Comment

I am using an app builder bassed on ionic framework and angular. it seems that get requests work, but this one does not... i tried changing to content-type application/json, and it did solve the problem with the characters changing, but the WS I am calling is throwing the same error: "Missing parameter token"

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.