[SOLVED] POST requests not working on IOS


#1

Hello! I’m having an issue with HTTP requests. Everything is working fine in Ionic View, browser and Android, but not working on IOS. GET requests are working fine on IOS, only POST methods bring errors. Any guesses, what can that be?

The project is currently on Ionic RC4, I can provide you with more information, just tell me what info do you need.
Thank you!

UPD: Tha backend receives blank body of a post request. Here’s what I get back:

ERROR: {"_body":"{“error”:“Sign up error”,“message”:{“first_name”:[“First Name cannot be blank.”],“last_name”:[“Last Name cannot be blank.”],“email”:[“Email cannot be blank.”],“device_id”:[“Device Id cannot be blank.”]}}",“status”:422,“ok”:false,“statusText”:“Bad Request”,“headers”:{“Content-Type”:[“application/json; charset=UTF-8”],“Pragma”:[“no-cache”]},“type”:2,“url”:“http://app.EDITED”}

My dependencies:

“dependencies”: {
"@angular/common": “2.2.1”,
"@angular/compiler": “2.2.1”,
"@angular/compiler-cli": “2.2.1”,
"@angular/core": “2.2.1”,
"@angular/forms": “2.2.1”,
"@angular/http": “2.2.1”,
"@angular/platform-browser": “2.2.1”,
"@angular/platform-browser-dynamic": “2.2.1”,
"@angular/platform-server": “2.2.1”,
"@ionic/cloud-angular": “0.7.0”,
"@ionic/storage": “1.1.7”,
"@types/moment-timezone": “0.2.32”,
“ionic-angular”: “2.0.0-rc.4”,
“ionic-native”: “2.4.1”,
“ionicons”: “3.0.0”,
“moment”: “2.15.1”,
“moment-timezone”: “0.5.7”,
“ng2-translate”: “5.0.0”,
“rxjs”: “^5.0.0-beta.12”,
“zone.js”: “0.6.26”
},
“devDependencies”: {
"@ionic/app-scripts": “^1.0.0”,
“sw-toolbox”: “^3.4.0”,
“typescript”: “2.0.9”
},

UPD2: Tried sending a POST request to HTTPS server and everything is fine


Ionic2 RC5, body removed from POST/PUT calls
#2

it would be helpful to show us the “errors”.


#3

Sorry, I must have written not clear enough. With “errors” I meant not the right behavior. Right now it seems like the backend receives request with blank body, so I’m adding tons of logs to the code to figure out where something might go wrong. I’ll try to keep this thread updated, just need some time for that.


#4

Updated the first post in this thread. Ask me if you need other info


#5

Try adding this to your index.html

<meta http-equiv=“Content-Security-Policy” content=“default-src ‘self’ gap://ready file://* *; style-src ‘self’ ‘unsafe-inline’; script-src ‘self’ ‘unsafe-inline’ ‘unsafe-eval’”/>


#6

I’ll try that later, thanks for the response. For now we moved our backend to https and everything’s fine


#7

You should stick with that. I believe Apple mandates use of TLS, and that may be what you banged into.


#8

Hi All, I am facing same issue. Can anybody please suggest the way out of this. Here is my code snippet

this.userPin = localStorage.getItem("User_Pin");
this.userEmail= localStorage.getItem("EMAIL");
let body = {
  PIN: this.userPin,
  email: this.userEmail
};
let data = JSON.stringify(body);

let headers = new Headers({ ‘Authorization’: ‘Basic xxxxxxxxxxxxx’ });
headers.append(‘Content-Type’, ‘application/json’);
this.http.post(“https://example/api”,data,{headers : headers})
.map(res => res.json())
.subscribe(res => {
}, (err) => {
});