首页 > 解决方案 > 使用 URL 中的参数发送 Post 请求

问题描述

任何注册后,我都会推动用户验证他的帐户。我将验证码发送到他的电子邮件,他将其添加到输入中并通过发布 API 调用发送该值。我的问题是,当我提出请求时,我得到了 203 Non-Authoritative Information 的响应。但是当我用 PostMan 尝试这个过程时,它工作正常

我的组件代码:

  verfiy(){

  this.code = this.userverfiycode.verfiCode;


this.authService.postData('Verify?userId='+this.user +'&vCode='+ this.code ).then((result) => {

  this.responseData = result;
  console.log(this.responseData);
  console.log(this.user);
  console.log(this.code);
  console.log(this.type);



  if (this.responseData = true) {

    this.pushpage()

  }

  else{

    console.log("");

      }
    }, (err) => {
     // Error log


    });

 }

我的提供者代码:

 let apiUrl = 'http://localhost:50494/api/Account/';
 let apiKey = 'sdf4rw-23fs-3454-fsdsd-3we2693243424';


 @Injectable()
 export class AuthProvider {




 constructor(public http : Http) {
 console.log('Hello AuthService Provider');



}

UserKey = localStorage.getItem('loginData');


postData( type) {
 return new Promise((resolve, reject) => {
  let headers = new Headers();
  headers.append('Content-Type', 'application/json');
  headers.append('token', apiKey);
  headers.append('api_key', this.UserKey);



   this.http.post(apiUrl + type, {headers: headers})
     .subscribe(res => {


      resolve();
      console.log()

    }, (err) => {
      reject(err);
      console.log()


    });
  });
}

标签: angularapiionic-frameworkionic3

解决方案


一般post()的第二个参数是data,第三个是{headers};

你能尝试发送一些虚拟数据吗

this.http.post(apiUrl + type, {}, {headers: headers})
     .subscribe(res => {});

我这么认为是因为后端没有获取您在 post() 函数中发送的标头。

您能否检查您的 devtool 网络选项卡是否有此请求,如果Request Headers运行正常


推荐阅读