首页 文章

Ionic 3 $ http.post返回空

提问于
浏览
1

我发送了一个带有Ionic的帖子到php服务器 . 服务器响应文本,但是当尝试获取它时,该对象为空 .

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

请求标头:

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

响应标头:

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

1 回答

  • 0

    你好,你可以使用 import { HTTP } from '@ionic-native/http'; 例如:

    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... 
    });
    

相关问题