1

I send a post with Ionic to php server. 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

1 Answer 1

1

Hi can you use 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... 
});
Sign up to request clarification or add additional context in comments.

1 Comment

ionic cordova plugin add cordova-plugin-advanced-http npm install --save @ionic-native/http Install these in your app folder

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.