# Ionic: How to work with native HTTP?

**URL:** <https://forum.ionicframework.com/t/ionic-how-to-work-with-native-http/98282>\
**Category:** Ionic Native\
**Created:** [July 15, 2017, 6:40am UTC](https://forum.ionicframework.com/t/ionic-how-to-work-with-native-http/98282 "2017-07-15T06:40:04Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![arnoldparge](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/arnoldparge/32/111355_2.png) [@arnoldparge](https://forum.ionicframework.com/u/arnoldparge)\
**Post date:** [July 15, 2017, 6:40am UTC](https://forum.ionicframework.com/t/ionic-how-to-work-with-native-http/98282/1 "2017-07-15T06:40:04Z")

</div>

I am unable to get the data from the server using [Native HTTP](https://ionicframework.com/docs/native/http/). The response on the server looks like:

[{feed\_id:“1”,feed\_title:“Helping the poor and needy people is a good deed”,feed\_date:“2017-07-14”,feed\_content:“Poverty is a signal of the failure to acquire suitable resources for the achievement of one’s ends.”,feed\_likes:“11”,feed\_comments:“12”,feed\_has\_image:“0”,feed\_img\_url:“no image”},{feed\_id:“2”,feed\_title:"Information technology in India ",feed\_date:“2017-07-12”,feed\_content:“Indias IT Services industry was born in Mumbai in 1967 with the establishment of the Tata Group in partnership with Burroughs. The first software export zone, SEEPZ – the precursor to the modern-day IT park – was established in Mumbai in 1973.”,feed\_likes:“20”,feed\_comments:“15”,feed\_has\_image:“0”,feed\_img\_url:“no image”}]

and my code is as follows:

```auto
this.http.get('my.php.url', {}, {})
			.then(data => {

				console.log(data.status);
				console.log(data.data); // data received by server
				console.log(data.headers);

				this.feeds = data.data;

			})
			.catch(error => {

				console.log(error.status);
				console.log(error.error); // error message as string
				console.log(error.headers);

			});

```

It is very difficult to check the error on device everytime I make change in the code.

below is the log I got from chrome://inspect/#devices

200 main.js:46602  
[{feed\_id:“1”,feed\_title:“Helping the poor and needy people is a good deed”,feed\_date:“2017-07-14”,feed\_content:“Poverty is a signal of the failure to acquire suitable resources for the achievement of one’s ends.”,feed\_likes:“11”,feed\_comments:“12”,feed\_has\_image:“0”,feed\_img\_url:“no image”},{feed\_id:“2”,feed\_title:"Information technology in India ",feed\_date:“2017-07-12”,feed\_content:“Indias IT Services industry was born in Mumbai in 1967 with the establishment of the Tata Group in partnership with Burroughs. The first software export zone, SEEPZ – the precursor to the modern-day IT park – was established in Mumbai in 1973.”,feed\_likes:“20”,feed\_comments:“15”,feed\_has\_image:“0”,feed\_img\_url:“no image”}] main.js:46603  
Object {X-Xss-Protection: “1; mode=block”, X-Android-Selected-Transport: “http/1.1”, Access-Control-Allow-Origin: “\*”, Date: “Sat, 15 Jul 2017 06:19:52 GMT”, Content-Length: “719”…}  
main.js:46604  
ERROR Error {} main.js:1362  
defaultErrorLogger main.js:1362  
ErrorHandler.handleError main.js:1422  
IonicErrorHandler.handleError main.js:113941  
ApplicationRef\_.tick main.js:5360  
(anonymous function) main.js:5233  
t.invoke polyfills.js:3  
inner.inner.fork.onInvoke main.js:4427  
t.invoke polyfills.js:3  
r.run polyfills.js:3  
NgZone.run main.js:4295  
ApplicationRef\_.\_this.\_zone.onMicrotaskEmpty.subscribe.next main.js:5233  
schedulerFn main.js:4129  
SafeSubscriber.\_\_tryOrUnsub main.js:36538  
SafeSubscriber.next main.js:36485  
Subscriber.\_next main.js:36425  
Subscriber.next main.js:36389  
Subject.next main.js:42443  
EventEmitter.emit main.js:4115  
NgZone.checkStable main.js:4392  
NgZone.setHasMicrotask main.js:4476  
inner.inner.fork.onHasTask main.js:4439  
t.hasTask polyfills.js:3  
t.\_updateTaskCount polyfills.js:3  
r.\_updateTaskCount polyfills.js:3  
r.runTask polyfills.js:3  
o

---

<div class="post-metadata">

**Author:** ![Sujan12](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sujan12/32/108395_2.png) [@Sujan12](https://forum.ionicframework.com/u/Sujan12)\
**Post date:** [July 17, 2017, 7:47am UTC](https://forum.ionicframework.com/t/ionic-how-to-work-with-native-http/98282/2 "2017-07-17T07:47:22Z")

</div>

Are you sure the response looks like that? That is JS, not JSON. (Validate with [jsonlint.com](http://jsonlint.com) to see what I mean.)

You should add a bit more info to your `console.log`: `console.log('data.status', data.status)` so we know what you are outputting here.

Include your `ionic info` output please.  
Post a screenshot of the error message please.

---

<div class="post-metadata">

**Author:** ![arnoldparge](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/arnoldparge/32/111355_2.png) [@arnoldparge](https://forum.ionicframework.com/u/arnoldparge)\
**Post date:** [July 17, 2017, 8:12am UTC](https://forum.ionicframework.com/t/ionic-how-to-work-with-native-http/98282/3 "2017-07-17T08:12:32Z")

</div>

I uesd angular http directly instead of ionic native http. Solved!  
Thanks for the reply though. 🙂  
BTW any thought on → [THIS POST](https://forum.ionicframework.com/t/how-to-upload-a-file-image-or-video-to-server-in-ionic/70097/7?u=arnoldparge)

---

<div class="post-metadata">

**Author:** ![castaway](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/castaway/32/112178_2.png) [@castaway](https://forum.ionicframework.com/u/castaway)\
**Post date:** [July 17, 2017, 9:03am UTC](https://forum.ionicframework.com/t/ionic-how-to-work-with-native-http/98282/4 "2017-07-17T09:03:23Z")

</div>

I can’t remember where I read or figured it out, I had a similar problem though - the Native HTTP doesnt seem to want to cope with a response that’s not an object - yours is an array. If the backend returned instead:

```auto
{"feeds":[...]}

```

It will work, that’s how I fixed mine.

---

<div class="post-metadata">

**Author:** ![mburger81](https://avatars.discourse-cdn.com/v4/letter/m/bc8723/32.png) [@mburger81](https://forum.ionicframework.com/u/mburger81)\
**Post date:** [August 9, 2017, 8:48pm UTC](https://forum.ionicframework.com/t/ionic-how-to-work-with-native-http/98282/5 "2017-08-09T20:48:57Z")

</div>

Hi, where you able to use POST and sending data to server? We are running into this error:

> [@How to use ionic native HTTP to perform a post with body and header](https://forum.ionicframework.com/t/how-to-use-ionic-native-http-to-perform-a-post-with-body-and-header/101449):
>
> We are trying to use Ionic Native HTTP which use codrova-HTTP, to do a simple get works very well, something like that: this.http.get('https://blabla.blabla.com/login', {}, {}) .then((data) =\> { console.log(data); }) .catch((error) =\> { console.log(error); }); But we can not do a POST with data and Content-Type header set. let data = { …

---

<div class="post-metadata">

**Author:** ![sparkingx250](https://avatars.discourse-cdn.com/v4/letter/s/ecccb3/32.png) [@sparkingx250](https://forum.ionicframework.com/u/sparkingx250)\
**Post date:** [August 25, 2017, 11:25pm UTC](https://forum.ionicframework.com/t/ionic-how-to-work-with-native-http/98282/7 "2017-08-25T23:25:00Z")

</div>

Is it possible at all to be able to use ionic native HTTP and be able to run in the browser? I would use angular Http but I need the background threading the native HTTP has

---

<div class="post-metadata">

**Author:** ![mburger81](https://avatars.discourse-cdn.com/v4/letter/m/bc8723/32.png) [@mburger81](https://forum.ionicframework.com/u/mburger81)\
**Post date:** [August 26, 2017, 2:14pm UTC](https://forum.ionicframework.com/t/ionic-how-to-work-with-native-http/98282/8 "2017-08-26T14:14:23Z")

</div>

Only for personal interest. Why do you need background threadinf? I’m not a security expert 🙂️

---

<div class="post-metadata">

**Author:** ![sparkingx250](https://avatars.discourse-cdn.com/v4/letter/s/ecccb3/32.png) [@sparkingx250](https://forum.ionicframework.com/u/sparkingx250)\
**Post date:** [August 26, 2017, 3:02pm UTC](https://forum.ionicframework.com/t/ionic-how-to-work-with-native-http/98282/9 "2017-08-26T15:02:00Z")

</div>

I want the app to be able to make HTTP requests even if the screen turns off or if its in the middle of the request I dont want it to stop because the screen turned off

---

<div class="post-metadata">

**Author:** ![sparkingx250](https://avatars.discourse-cdn.com/v4/letter/s/ecccb3/32.png) [@sparkingx250](https://forum.ionicframework.com/u/sparkingx250)\
**Post date:** [August 26, 2017, 3:04pm UTC](https://forum.ionicframework.com/t/ionic-how-to-work-with-native-http/98282/10 "2017-08-26T15:04:01Z")

</div>

For example, my app updates the users location in real time but if the screen turns off then it will stop doing the HTTP POST request and the users location does not get updated. does that make sense?

---

<div class="post-metadata">

**Author:** ![rlwt](https://avatars.discourse-cdn.com/v4/letter/r/8797f3/32.png) [@rlwt](https://forum.ionicframework.com/u/rlwt)\
**Post date:** [August 27, 2017, 10:48am UTC](https://forum.ionicframework.com/t/ionic-how-to-work-with-native-http/98282/11 "2017-08-27T10:48:38Z")

</div>

does it work in ios too ?

---

<div class="post-metadata">

**Author:** ![Sujan12](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sujan12/32/108395_2.png) [@Sujan12](https://forum.ionicframework.com/u/Sujan12)\
**Post date:** [August 27, 2017, 3:36pm UTC](https://forum.ionicframework.com/t/ionic-how-to-work-with-native-http/98282/12 "2017-08-27T15:36:46Z")

</div>

> [@rlwt](#):
>
> does it work in ios too ?

What “it” are you asking about?

---

<div class="post-metadata">

**Author:** ![mburger81](https://avatars.discourse-cdn.com/v4/letter/m/bc8723/32.png) [@mburger81](https://forum.ionicframework.com/u/mburger81)\
**Post date:** [October 5, 2017, 3:46pm UTC](https://forum.ionicframework.com/t/ionic-how-to-work-with-native-http/98282/13 "2017-10-05T15:46:52Z")

</div>

this is not working in background, there are problems on android and ios working on background. Have a look on cordova background services and something like that
