Ionic 2 RC3 http 404 not found (from cache)


#1

Hello,

My probleme is when I send a Post with my laptop (windows or linux) all is OK but when I try with my phone I have this message :

POST http://www.myserver.fr/folder/php/user.php 404 (Not Found)


Status Code:404 Not Found (from cache)


cache-control:no-store; no-cache; must-revalidate
content-type:application/json
Origin:file://

My config.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget id="com.ionicframework.myapp5958001" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
  <name>myApp5</name>
  <description>An awesome Ionic/Cordova app.</description>
  <author email="hi@ionicframework" href="http://ionicframework.com/">Ionic Framework Team</author>
  <content src="index.html"/>
  <access origin="*"/>
  <allow-intent href="http://*/*"/>
  <allow-navigation href="http://www.myserver.fr/folder/*" />
  <allow-intent href="https://*/*"/>
  <allow-intent href="tel:*"/>
  <allow-intent href="sms:*"/>
  <allow-intent href="mailto:*"/>
  <allow-intent href="geo:*"/>
  <platform name="android">
    <allow-intent href="market:*"/>
  </platform>
  <platform name="ios">
    <allow-intent href="itms:*"/>
    <allow-intent href="itms-apps:*"/>
  </platform>
  <preference name="webviewbounce" value="false"/>
  <preference name="UIWebViewBounce" value="false"/>
  <preference name="DisallowOverscroll" value="true"/>
  <preference name="android-minSdkVersion" value="16"/>
  <preference name="BackupWebStorage" value="none"/>
  <preference name="SplashMaintainAspectRatio" value="true"/>
  <preference name="FadeSplashScreenDuration" value="300"/>
  <feature name="StatusBar">
    <param name="ios-package" onload="true" value="CDVStatusBar"/>
  </feature>
  <plugin name="cordova-plugin-device" spec="~1.1.3"/>
  <plugin name="cordova-plugin-console" spec="~1.0.4"/>
  <plugin name="cordova-plugin-whitelist" spec="~1.3.0"/>
  <plugin name="cordova-plugin-splashscreen" spec="~4.0.0"/>
  <plugin name="cordova-plugin-statusbar" spec="~2.2.0"/>
  <plugin name="ionic-plugin-keyboard" spec="~2.2.1"/>
</widget>

My function

	let headers = new Headers();
	// headers.append("Content-Type", 'application/x-www-form-urlencoded');
	headers.append("Content-Type", 'application/json');
	headers.append("Cache-Control", 'no-store; no-cache; must-revalidate');

	let options = new RequestOptions({
		method: RequestMethod.Post,
		url: "http://www.myserver.fr/folder/php/user.php",
		headers: headers,
		body: JSON.stringify(trans)
	});

	return this.http.request(new Request(options))
		.map((res : Response)=>{
				if (res) {
					return [{ status: res.status, json: res.json() }]
				}
            });

My php header

header("Content-Type: application/json");
  header("Cache-Control: no-cache, must-revalidate"); //HTTP 1.1
  header("Pragma: no-cache"); //HTTP 1.0
  header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
header("Access-Control-Allow-Origin: *"); 
header("Access-Control-Allow-Headers: content-type, Cache-Control"); 
header("Access-Control-Allow-Methods: GET,POST"); 

My ionic info

Cordova CLI: 6.4.0
Gulp version:  CLI version 1.2.2
Gulp local:
Ionic CLI Version: 2.1.4
Ionic App Lib Version: 2.1.2
OS:
Node Version: v6.9.1

Could someone help me very thanks in advance

Thierry


#2

Sorry, just a last thing with RC2 all was OK

"dependencies": {
  "@angular/common": "2.1.1",
  "@angular/compiler": "2.1.1",
  "@angular/compiler-cli": "2.1.1",
  "@angular/core": "2.1.1",
  "@angular/forms": "2.1.1",
  "@angular/http": "2.1.1",
  "@angular/platform-browser": "2.1.1",
  "@angular/platform-browser-dynamic": "2.1.1",
  "@angular/platform-server": "2.1.1",
  "@ionic/storage": "1.1.6",
  "ionic-angular": "2.0.0-rc.2"
},
"devDependencies": {
  "@ionic/app-scripts": "0.0.39"
}

RC3

  "dependencies": {
    "@angular/common": "2.1.1",
    "@angular/compiler": "2.1.1",
    "@angular/compiler-cli": "2.1.1",
    "@angular/core": "2.1.1",
    "@angular/forms": "2.1.1",
    "@angular/http": "2.1.1",
    "@angular/platform-browser": "2.1.1",
    "@angular/platform-browser-dynamic": "2.1.1",
    "@angular/platform-server": "2.1.1",
    "@ionic/storage": "1.1.6",
    "ionic-angular": "2.0.0-rc.3",
    "ionic-native": "2.2.3",
    "ionicons": "3.0.0",
    "rxjs": "5.0.0-beta.12",
    "zone.js": "0.6.26",
    "ts-md5": "1.2.0"
  },
  "devDependencies": {
    "@ionic/app-scripts": "0.0.45"
  },

#3

I’m not sure, I rewrite a part of my script and now all it’s Ok.

In fact, I havent rewrite a lot and I’m not certain of the solution.

But I think it was another script that created the problem.

Old script

myData.ts

postJsonPorte(trans) {
var json = JSON.stringify(trans);
var headers = new Headers();
headers.append(‘Content-Type’,‘text/plain’);

return new Promise(resolve => {
  this.http.post("http://www.myserver.fr/folder/php/porte.php",json,{headers : headers})
    .map(res => res.json())
    .subscribe(dataPost => {
  	this.dataPost = dataPost;
  	resolve(this.dataPost);
    });
});

}

page.ts

this.myData.postJsonPorte(dataItems).then(data => {
....
 });

New script

myData.ts

postJsonPorte(trans) {
let headers = new Headers();
headers.append(“Content-Type”, ‘application/json’);
headers.append(“Cache-Control”, ‘no-store; no-cache; must-revalidate’);

let options = new RequestOptions({
method: RequestMethod.Post,
url: “http://www.myserver.fr/folder/php/porte.php”,
headers: headers,
body: JSON.stringify(trans)
});

return this.http.request(new Request(options))
.map((res : Response)=>{
if (res) {
return [{ status: res.status, json: res.json() }]
}
});
}

page.ts

this.myData.postJsonPorte(dataEnv).subscribe(res => {

});

If that can help someone.


#4

I have the same problem.
Everything was all right when I used “@angular/http”: "2.0.0-rc.4"
But it does not work on “@angular/http”: “2.2.1”


#5

I use ionic 2 RC4 now with “@angular/http”: “2.2.1” and the script that I wrote above work well, I think you have to check your script and think about ngModule.


#6

I found this problem happened after I upgraded cordova version to 6.4.
I searched the Internet, lots of people say that I need to add cordova-whitelist plugin to my project and change config.xml. But I still can’t connect server on my phone. Even it works alright on the browser of the phone.


#7

hi Reikami,

cordova-whitelist it’s add when you create your project by ionic (you have ionic 2 ?). Lots of people invent a lot of thing.

I haven’t change anything in whitelist and config.xml.

This my actual config :
Cordova CLI: 6.4.0
Ionic CLI Version: 2.1.17
Ionic App Lib Version: 2.1.7
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Windows 10
Node Version: v6.9.1
Xcode version: Not installed

Do a check with “ionic info” in your CMD.

create a new project with “ionic start --v2 myApp” and test just your script for the Post and Get.

Best way it’s to do simple.
If you reply thanks to post your “ionic info”.
And give me more describe about your problem (console.log, error, …)