I’ve got a problem. If I run android with the command:
$ionic run --livereload android
My App works fine.
But if i install the .apk or use the command:
$ionic run android
I can use “GET-function” but the “POST-funktion”, dont work!
I seach for some solution but i dont find somthing. I change the config.xml at the path C://MyAPP/config.xml and add this →
<content src="index.html"/>
But it still dont work.
This is my Code :
$scope.mtahinzubtn=function(){ // Just a Button
// some Var
var nameVar = document.getElementById('name'); // string
var vornameVar = document.getElementById('vorname'); // string
var stadtVar = document.getElementById('stadt');//string
var adresseVar = document.getElementById('adresse');//string
var personIDVar = document.getElementById('personID');//number
// Jason Array
var dataj ={address:adresseVar.value,city:stadtVar.value,firstName:vornameVar.value,lastName:nameVar.value,personID:personIDVar.value};
alert("Ausgabe der Variablen : "+nameVar.value+" "+vornameVar.value+" "+stadtVar.value+" "+adresseVar.value+" "+personIDVar.value); // ZUM testen Ausgabe der Variable
$http.post('http://192.168.2.103:8080/JAXRS-HelloWorld/rest/visitors/insertvisitor',JSON.stringify(dataj)).then(function(resp) {
console.log('Success', JSON.stringify(resp));
alert("Erfolg"+JSON.stringify(resp));
// For JSON responses, resp.data contains the result
}, function(err) {
console.log('Error', JSON.stringify(err));
alert("Error"+JSON.stringify(err));
// err.status will contain the status code
})};
If i run the app via .apk i get this alert message:
Error{“data”:“”,status":403,“config”:{“method”:“POST”,transformRequest":[null],“transformRespnse”:[null],“url”:“http://192.168.2.103:8080/JAXRS-HelloWorld/rest/visitors/insertvisitor",data":"{\“address\”:\“testvalu\”,\“city”:\“testcity\”,\"firstName:\“bob\”,\“lastName\”:“Hink\”,\“personID\”:\“123\”}”,“headers:{“Accept”:application/json,text/plain,/”,“Content-Typ”:“application/json;charset=utf-8”}},“statusText”:“Forbidden”}
If I run android with the command
$ionic run --livereload android
My App works fine.
Erfolg{"data":[{"HTTP_CODE":"200"}],"status":200,"config":{"method":"POST","transformRequest":[null],"transformResponse":[null],"url":"http://192.168.2.103:8080/JAXRS-HelloWorld/rest/visitors/insertvisitor","data":"{\"address\":\"deadead\",\"city\":\"deadea\",\"firstName\":\"dedaedea\",\"lastName\":\"deadea\",\"personID\":\"123\"}","headers":{"Accept":"application/json,
text/plain,
/","Content-Type":"application/json;charset=utf-8"}},"statusText":"OK"}
I knowe my english is not good but you welcome to correct me