Reputation: 55
I've got problem with my application. I create app in angular and wrap with cordova. In android simulator request url is good but when I copy files and test in my mobile phone, url is wrong.
My request: http://111.111.11.111/myReq - good
On my phone, after Cordova build: file:///android_asset/www/null/login -bad
And this my error:
POST file:///android_asset/www/null/login net::ERR_FILE_NOT_FOUND
I try the solution:
ng build --prod
and cordova build --prod
This is my request:
userLogin(login: string, password: string): Observable<any> {
const baseUrl = 'http://111.111.11.111/myReq'
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
'Authorization': 'myToken',
})
};
return this.http.post<any>(`${baseUrl}/login`, JSON.stringify({login, password}), httpOptions);
}
and nothing work. How can I fix it?
Upvotes: 0
Views: 562
Reputation: 2363
Since my assumption was correct I'll give a real answer, create another variable that contains the full url that will receive the POST request
const requestUrl = `${baseUrl}/login`
return this.http.post<any>(requestUrl, JSON.stringify({login, password}), httpOptions)
If for any reason the template variable is not working for you ( do a console log to check the value ), just concat the two strings like follow
const requestUrl = baseUrl + '/login'
return this.http.post<any>(requestUrl, JSON.stringify({login, password}), httpOptions)
Upvotes: 2