简体   繁体   English

离子3 $ http.post返回空

[英]Ionic 3 $http.post return empty

I send a post with Ionic to php server. 我将与Ionic的帖子发送到php服务器。 The server response a text plain but when a try get it, the object is empty. 服务器以纯文本形式响应,但尝试获取时,该对象为空。

var response = $http.post('https://somthing.com', $rootScope.data);
console.log(response);
return response;

Request headers: 请求标头:

Host: something.com
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:62.0) Gecko/20100101 Firefox/62.0
Accept: application/json, text/plain, */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Referer: http://localhost:8101/
Content-Type: application/x-www-form-urlencoded;charset=utf-8
Content-Length: 137
Origin: http://localhost:8101
Connection: keep-alive

Response headers: 响应头:

HTTP/1.1 200 OK
Date: Tue, 23 Oct 2018 06:39:22 GMT
Server: Apache
Cache-Control: no-cache, private
Content-Encoding: gzip
Vary: Accept-Encoding,User-Agent
Cache-Control: max-age=2592000
Expires: Thu, 22 Nov 2018 06:39:21 GMT
Keep-Alive: timeout=3, max=500
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8

Hi can you use import { HTTP } from '@ionic-native/http'; 您好,您可以使用import { HTTP } from '@ionic-native/http'; example: 例:

constructor(... public http: HTTP){}

var url = 'https://somthing.com';
var data = {'form': form};
var headers = {'Accept' : 'application/x-www-form-urlencoded',
              'Content-Type' : 'application/x-www-form-urlencoded'};

this.http.post(url, data, headers).then((data) => {
  #actions...
}, error => {
  console.log(error);
  #actions... 
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM