0

I have a post request that sends some token post parameters. Value token doesn't surrounded with any quotes. But, when making http request, the token get automatically wrapped with single/double quotes.

Here's the code that makes $http POST request,

var data = { YII_CSRF_TOKEN : token};
console.info(token);
$http.post('..some url here..', data).success (function (response){

});

BTW, Logging the token gives me the token which has no quotes wrapped.

Current result,

enter image description here

You could see the value of token gets automatically surrounded with quotes.

My expected output to be like,

enter image description here

Yuva Raj
  • 3,881
  • 1
  • 19
  • 30
Kalpana
  • 17
  • 3
  • Are you just talking about the quotes in the console? Or it really is sending to the server with the quotes? – choz Jul 22 '16 at 05:15
  • Not in console. But Yes, it sending to the server with the quotes. – Kalpana Jul 22 '16 at 05:18
  • that what json stringify does.. if you dont want to send json.. change the `contentType` to `application/text` – harishr Jul 22 '16 at 05:19
  • 1
    The token (or `YII_CSRF_TOKEN` in your JSON) is a string and therefore **must** be quoted. It appears the server is expecting `application/x-www-form-urlencoded` – Phil Jul 22 '16 at 05:19
  • If that `console.info` returns value like `"18v789uh"`, then your `token` must be wrapped in quotes as well. Such as `token = '"18v789uh"'`. – choz Jul 22 '16 at 05:19
  • See [this answer](http://stackoverflow.com/a/30970229/283366) in the duplicate question – Phil Jul 22 '16 at 05:22
  • @Phil thanks, that helped. – Kalpana Jul 22 '16 at 05:33

0 Answers0