Download text/csv content as files from server in Angular

$http service returns a promise which has two callback methods as shown below. $http({method: ‘GET’, url: ‘/someUrl’}). success(function(data, status, headers, config) { var anchor = angular.element(‘<a/>’); anchor.attr({ href: ‘data:attachment/csv;charset=utf-8,’ + encodeURI(data), target: ‘_blank’, download: ‘filename.csv’ })[0].click(); }). error(function(data, status, headers, config) { // handle error });

How to properly use Bearer tokens?

1.Improving the security because if token is not sent in the header that sent in url, it will be logged by the network system, the server log …. 2.A good function to get Bearer tokens /** * Get header Authorization * */ function getAuthorizationHeader(){ $headers = null; if (isset($_SERVER[‘Authorization’])) { $headers = trim($_SERVER[“Authorization”]); } else …

Read more

What is the most appropriate HTTP status code to return if a required header is missing?

400 Bad Request It’s a user error in the request. Unlike with a 403, the client should be allowed to repeat their request, but only after modification: 10.4.1 400 Bad Request The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications. Edit As …

Read more

Detecting the character encoding of an HTTP POST request

the default encoding of a HTTP POST is ISO-8859-1. else you have to look at the Content-Type header that will then look like Content-Type: application/x-www-form-urlencoded ; charset=UTF-8 You can maybe declare your form with <form enctype=”application/x-www-form-urlencoded;charset=UTF-8″> or <form accept-charset=”UTF-8″> to force the encoding. Some references :

Apache: difference between “Header always set” and “Header set”?

What is the difference between Header always set and Header set in Apache? As the quoted bit from the manual says, without ‘always’ your additions will only go out on succesful responses. But this also includes “successfully” forward errors via mod_proxy and perhaps other similar handlers that roughly act like proxies. What generates your 404s …

Read more