Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k 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 Reply

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...