Reputation: 18144
I have to send the parameter value 'AbCd/EfgH'
as is. But angular escaping the '/'
to %2F
. I don't have control over the URL
.
What's the best approach to this problem?
I don't want to force angular to stop encoding all other URLs.
$http.get(URL, {
params: {
emv_ref: 'AbCd/EfgH',
email: email
}
});
Upvotes: 2
Views: 711
Reputation: 193261
Angular URL encodes all parameters, you can't just exclude one from this process. you just need to manually compose URL with necessary parameters. Use convenient $httpParamSerializer service to serialize part of your parameters and append non-encoded to the string of params:
var params = $httpParamSerializer({email: email}) + '&emv_ref=AbCd/EfgH';
$http.get(URL + '?' + params);
Or much cleaner approach would be to use custom paramSerializer function:
$http.get(URL, {
paramSerializer: function(params) {
return $httpParamSerializer({email: email}) + '&emv_ref=AbCd/EfgH';
}
});
.. or like this:
$http.get(URL, {
params: {
email: email,
emv_ref: 'AbCd/EfgH'
},
paramSerializer: function(params) {
var ref = '&emv_ref=' + params.emv_ref;
delete params.emv_ref;
return $httpParamSerializer(params) + ref;
}
});
Upvotes: 1