使用网址中的参数发送发布请求

时间:2018-10-09 21:45:04

标签: angular api ionic-framework ionic3

注册后,我会推送用户以验证其帐户。我将验证码发送到他的电子邮件,他将其添加到输入中,并通过post API调用发送该值。 我的问题是,当我发出请求时,得到的响应是203非权威信息。但是,当我使用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()


    });
  });
}

1 个答案:

答案 0 :(得分:2)

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

您可以尝试发送一些虚拟数据吗?

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

我想是因为后端没有在post()函数中获取要发送的标头。

如果Request Headers运行正常,能否请您检查一下devtool网络标签上的请求

相关问题