【问题标题】:Send Post request with parameters in URL使用 URL 中的参数发送 Post 请求
【发布时间】:2019-03-14 17:57:40
【问题描述】:

在任何注册后,我都会推动用户验证他的帐户。我将验证码发送到他的电子邮件,他将其添加到输入中并通过发布 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()


    });
  });
}

【问题讨论】:

  • 你也可以在这里发布邮政编码
  • 帖子数据中没有正文。这是正确的吗?
  • 我只想在 Url 中发送参数

标签: angular api ionic-framework ionic3


【解决方案1】:

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

你可以尝试发送一些虚拟数据

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

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

如果Request Headers 运行正常,请检查您的 devtool 网络选项卡以获取此请求

【讨论】:

  • 请记住 post() 第二个参数是 body/form-date,在第三个参数中我们发送选项。由于在您的情况下表单数据为空,因此发送空对象。希望你明白其中的逻辑
  • 请接受这个答案是正确的,它可能会帮助其他有类似问题的人。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-04-23
  • 2018-12-14
  • 2015-07-22
  • 2019-12-04
  • 2019-02-02
  • 2013-04-20
  • 2018-06-29
相关资源
最近更新 更多