相关疑难解决方法(0)

Angular2 - Http POST请求参数

我正在尝试发出POST请求,但我无法让它工作:

testRequest() {
      var body = 'username=myusername?password=mypassword';
      var headers = new Headers();
      headers.append('Content-Type', 'application/x-www-form-urlencoded');

      this.http
        .post('/api',
          body, {
            headers: headers
          })
          .subscribe(data => {
                alert('ok');
          }, error => {
              console.log(JSON.stringify(error.json()));
          });
}
Run Code Online (Sandbox Code Playgroud)

我基本上想要复制这个http请求(不是ajax),就像它是由html表单生成的:

网址:/ api

参数:用户名和密码

typescript angular

86
推荐指数
6
解决办法
19万
查看次数

标签 统计

angular ×1

typescript ×1