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.1k views
in Technique[技术] by (71.8m points)

ionic framework - Http Post Angular 9 Params

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'=>'[email protected]', 'password'=>'somepass')

But when i tried post from angular i get nothing

const params = new HttpParams();
params.set('email', '[email protected]');
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

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

1 Answer

0 votes
by (71.8m points)

You should Write code like below-

const params = new HttpParams({ fromObject: { email: [email protected], password: somepass, anotherParam: value}});

In your case following also might work.

const params = new HttpParams()set('email', '[email protected]').set('password', 'somepass');

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


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

...