$http post data appended to URL - angularjs

I have below $http.post request
var credentials = {username: "alpha", password: "beta"}
$http({
method: 'POST',
url: baseUrl
params: credentials
paramSerializer: '$httpParamSerializerJQLike',
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
});
This works fine but all credentials appended in the URL which was not a good approach as it display sensitive data
BUT when I change this to
$http({
method: 'POST',
url: baseUrl,
data: credentials,
headers: {'Content-Type': 'multipart/form-data'}
});
this does not work?
what Is the issue?
if we do not send any headers than in browser I can see the default
Content-Type:application/json;charset=UTF-8
so why exactly server do not accept this application/json ?
Is that issue related to server or on the angular side?

$http({
method: 'POST',
url: baseUrl,
data: $httpParamSerializerJQLike(credentials),
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
});

Related

I can't able to read the response from the server in angularjs code

I can't able to read the response from the server in angularjs code. in $http methode , but in chrome inspect network option , i can sea the request and response.
My code is
$http({
method: 'POST',
url: url,
data: data,
responseType: 'arraybuffer',
}).then(function successCallback(res) {
console.log('---res', res);
}, function errorCallback(res) {
console.log('---err', res);
});
$http({
method: 'POST',
url: url,
data: data,
responseType: 'arraybuffer',
transformResponse: appendTransform($http.defaults.transformResponse, function(value) {
return doTransform(value);
})
});
above code worked for me

Getting 415(unsupported media type ) in ajax formdata post resuest to spring

Want to send image data through ajax to the controller .But error 415 gets .I am using angular js and send images to the controller . But error ocurs . Please help
fd= new FormData();
fd.append("image", imageall);
call(fd);
});
}
function call(fd){
$http({
method: 'POST',
contentType: "application/json; charset=utf-8",
url: "./WQF00069/update.app",
data: fd,
processData: false,
enctype:'multipart/form-data',
transformRequest: angular.identity,
cache: false,
timeout: 600000,
headers: { 'Content-Type': undefined},
}).success(function(data) {
Flash.create('info', ' Update Success Fully ', 'large-text');
`enter code here`
}).error(function(response){
console.dir(response);
Flash.create('danger','There is a Problem.Contact With Administrator', 'large-text');
});
}

Converting AngularJS $http request to Angular2 POST

I have the following Angular 1.5 $http request:
this.$http({
method: 'POST',
url: "example.com",
data: {
"action" : "myAction"
},
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
transformRequest: function(obj) {...}
});
And I'm trying to rewrite it to Angular2, but I don't know how the "data" and "transformRequest" properties translate. So far I have:
let options = new RequestOptions({
method: RequestMethod.Post,
headers: myHeader
});
this.http.post(
'example.com',
options
);
How can I add the Angular2 equivalent of "data" and "transformRequest"?

$q.all promises inject data from first promise to second promise

i would like to know if it's possible here with $q.all:
var promise1 = $http({
method: 'GET',
url: "https://cubber.zendesk.com/api/v2/organizations/"+id+"/users.json",
dataType: 'json',
headers: {'Content-Type': 'application/json',
'Authorization': 'Bearer '+token}
})
var promise2 = $http({
method: 'GET',
url: "https://cubber.zendesk.com/api/v2/users/"+idname+"/tickets/requested.json",
dataType: 'json',
headers: {'Content-Type': 'application/json',
'Authorization': 'Bearer '+token}
});
$q.all([promise1, promise2]).then(function(data){
console.log(data[0], data[1]);
});
If it's possible to retrieve data from promise 1 and inject into the url of promise 2 and then retrieve full data of both promises in the same array ?
For example like this
var responses = [];
$http({ ... }).then(function (response) {
responses.push(response);
return $http({ ... });
}).then(function (response) {
responses.push(response);
console.log(responses[0], responses[1]);
});
See also this answer, with many different ways to handle it.

Getting "ERR_EMPTY_RESPONSE" after first http request to Dreamfactory

I'm trying to make an http request to a Dreamfactory backend.
return this.$http({
method: "GET",
url: "http://.../DMO_emails?filter=nom%20LIKE%20%27xxx%25%27%20OR%20nom%20LIKE%20%27%25%20xxx%25%27",
headers: {
"X-Dreamfactory_Application-Name": "appName"
});
After the first request, any request returns an error:
net::ERR_EMPTY_RESPONSE
Change this
return this.$http({
method: "GET",
url: http://.../DMO_emails?filter=nom%20LIKE%20%27xxx%25%27%20OR%20nom%20LIKE%20%27%25%20xxx%25%27,
headers: {
"X-Dreamfactory_Application-Name": "appName"
});
to this
return $http({
method: "GET",
url: "http://.../DMO_emails?filter=nom%20LIKE%20%27xxx%25%27%20OR%20nom%20LIKE%20%27%25%20xxx%25%27",
headers: {
"X-Dreamfactory_Application-Name": "appName"
}
});

Resources