Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

how to change post['Content-Type'] in angularjs

i want to change post['Content-Type'] in angularjs so i use

  app.config(function($locationProvider,$httpProvider) {
$locationProvider.html5Mode(false);
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
$httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;        charset=UTF-8';
 });

and the event is

     $http.post("http://172.22.71.107:8888/ajax/login",{admin_name:user.u_name,admin_password:user.cert})
        .success(function(arg_result){

            console.log(arg_result);


        });
};

however the rusult is

Parametersapplication/x-www-form-urlencoded
{"admin_name":"dd"} 

what i want is

Parametersapplication/x-www-form-urlencoded
 admin_name dd

so what i should do?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try like:

var serializedData = $.param({admin_name:user.u_name,admin_password:user.cert});

$http({
    method: 'POST',
    url: 'http://172.22.71.107:8888/ajax/login',
    data: serializedData,
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
    }}).then(function(result) {
           console.log(result);
       }, function(error) {
           console.log(error);
       });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...