角度发送没有标头的HTTP POST请求

时间:2017-05-12 21:53:43

标签: angular http ionic-framework

我想让Angular(我使用4.0.2 fwiw)发送一个非常小的HTTP POST请求。默认情况下,例如如果我运行这样的代码:

import { Http, Response } from '@angular/http';
export class MyService {
  constructor(public http: Http) {
    this.http.post("http://some_url/", "{}");
  }  
}

我的应用程序发送到some_url的HTTP请求标头的很多。我想发送最小的最小值,因为有问题的服务器实际上非常关心关于此应用程序的请求标头。我看到所有这些标题,就像我的有效载荷大小100倍一样。

Accept:application/json, text/plain, */*
Accept-Encoding:gzip, deflate
Accept-Language:en-US
Connection:keep-alive
Content-Length:2
content-type:text/plain
Host:192.168.4.1
Origin:file://
User-Agent:Mozilla/5.0 (Linux; Android 7.0; SM-G930V Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/58.0.3029.83 Mobile Safari/537.36
X-DevTools-Emulate-Network-Conditions-Client-Id:ed111a30-afdb-4b86-9717-d5f22a18d8e5
X-DevTools-Request-Id:20251.498
X-Requested-With:com.ionicframework.myapp123456

1 个答案:

答案 0 :(得分:0)

您的请求可能采用了表单编码,因此您应该设置标题:
{'Content-Type':'application / x-www-form-urlencoded'}

相关问题