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

Categories

I tried to post my email and password on login method but every time get empty params after response

With curl, I sent it and everything worked

curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post))

where $post

array('email'=>'some@gmail.com', 'password'=>'somepass')

But when i tried post from angular i get nothing

const params = new HttpParams();
params.set('email', 'some@gmail.com');
params.set('password', 'somepass');


this.http.post('https://myurl.com/login', '', {
   params: params
}).subscribe((data) => console.log(data))
question from:https://stackoverflow.com/questions/65918778/http-post-angular-9-params

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.2k views
Welcome To Ask or Share your Answers For Others

1 Answer

You should Write code like below-

const params = new HttpParams({ fromObject: { email: some@gmail.com, password: somepass, anotherParam: value}});

In your case following also might work.

const params = new HttpParams()set('email', 'some@gmail.com').set('password', 'somepass');

You can see request header in network tab like below enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...