Hello,
i am trying to create an login app
in order to receive token from a webservice.
Can anyone help me out?
Check the documentation of the webservice you use. This will explain how to use it.
the problem is that i got issues with the syntax in the ionic âŚ
What code do you already have?
Show us that + the place where the syntaxerror happens
import { Component, ViewChild } from â@angular/coreâ;
import { Nav, Platform } from âionic-angularâ;
import { StatusBar } from â@ionic-native/status-barâ;
import { SplashScreen } from â@ionic-native/splash-screenâ;
import {HttpParams,HttpClient} from â@angular/common/httpâ;
import { HomePage } from ââŚ/pages/home/homeâ;
import { ListPage } from ââŚ/pages/list/listâ;
import {DemoService} from â./demo.serviceâ;
@Component({
templateUrl: âapp.htmlâ,
selector:âmy-appâ,
template:`
Demo App
foods
- {{food.name}}
export class Appcomponent{
name:string;
constructor(private http:HttpClient) {
this.http.get(âhttp://192.168.0.6:81/EBSWebApi/api/login/â);
let params = new HttpParams();
params = params.append(âSubscriptionIDâ, â3Dâ);
params = params.append(âSubscriptionPasswordâ, âpassxâ);
params = params.append(âBridgeIDâ, ââ);
params = params.append(âUserIDâ, âkhcadminâ);
params = params.append(âPasswordâ, âP@ssw0rdâ);
params = params.append(âBranchIDâ, â01â);
params = params.append(âLangIDâ, âen-USâ);
}
but you called get before the setup âŚ
in my code
var u='http://'+self.ourserveraddress+'/files?'+encodeURI(urlstring);
this.http.get(u,{},{})
.then(function(response)
if u need to pass params, then you have to add stuff to the api request parms,
where i have {}
var u=âhttp://â+self.ourserveraddress+â/files?â+encodeURI(urlstring);
this line is made up for what exactly reason?
i donât understand the question. i used a variable because I wanted to
the POINT was that you needed to pass some parameters to the request, but didnât
You may have to change your way to consume your web service, change the âgetâ method to âpostâ.
The code I use to consume a web service is like this :
constructor(private http:Http)
{
//your code here
}
To consume a web service :
this.http.post("http://address_and_methodName_of_my_webservice", "my parameter in JSON format",getOptions())
.subscribe(restp=>{//your code here if you can correctly consume your ws}
.err=>alert(err)
);
my custom web service has 4 http methods
get, post, put and delete
post and put take a body, get and delete do not
âgetâ and âpostâ are the same method
not⌠get does NOT take a body, and is an operation to get data FROM the endpoint.
post is an operation to SEND data TO the endpoint. (above URL parms, this is called a request body)
the get method takes a body but the itâs visible in the url address, the trouble is the fact that you canât count on the get method to send advanced data, like json or xml files, only some basic text.
get also sends data to an endpoint
ok, granted, you CAN send body data with GET ⌠never seen it used that way
well and how am i supposed to add my parameters?
the doc on http get says
get(url, parameters, headers)
and parameters and headers are objects, not strings
so (I canât find what HttpParams object does)
let params = {
âSubscriptionIDâ: â3Dâ,
'SubscriptionPasswordâ: âpassxâ,
âBridgeIDâ: '',
'UserIDâ, âkhcadminâ,
âPasswordâ: âP@ssw0rdâ,
âBranchIDâ: â01â,
âLangIDâ: âen-USâ};
this.http.get(âhttp://192.168.0.6:81/EBSWebApi/api/login/â, params);
i used a similar code,
it worked better ,
many thanks for your help but
i am still getting an issue.
I uploaded a screenshot with the issue as you can see
ok, you need an http header set⌠that is the last parm of the http get
the message tells you which header⌠I will let you research it (google search)
// in folder -> app/providers/loginservice/loginservice.ts
import { HttpClient } from â@angular/common/httpâ;
import { Injectable } from â@angular/coreâ;
import ârxjs/add/operator/mapâ;
import {Observable} from ârxjs/Observableâ;
@Injectable()
export class LoginServiceProvider {
url;
params : {
SubscriptionID: string;
SubscriptionPassword: string;
BridgeID: string;
UserID: string;
Password: string;
BranchID: string;
LangID: string;
}
constructor(public http: HttpClient) {
console.log(âHello LoginServiceProvider Providerâ);
this.url=âhttp://192.168.0.6:81/EBSWebApiâ;
}
getLogin(SubscriptionID,SubscriptionPassword,BridgeID,
UserID,Password,BranchID,LangID):Observable{
return this.http.get(this.url,)
}}
// in different folder -> app/pages/home/home.ts
import { Component } from â@angular/coreâ;
import { NavController } from âionic-angularâ;
import {LoginServiceProvider} from ââŚ/âŚ/providers/login-service/login-serviceâ;
@Component({
selector: âpage-homeâ,
templateUrl: âhome.htmlâ
})
export class HomePage {
params : {
SubscriptionID: string;
SubscriptionPassword: string;
BridgeID: string;
UserID: string;
Password: string;
BranchID: string;
LangID: string;
}
constructor(public navCtrl: NavController,
private loginServiceprovider:LoginServiceProvider) {
}
ionViewWillEnter(){
this.params={
SubscriptionID: â3Dâ,
SubscriptionPassword: âpassxâ,
BridgeID: ââ,
UserID: âkhcadminâ,
Password: âP@ssw0rdâ,
BranchID: â01â,
LangID: âen-USâ
};
this.loginServiceprovider.getLogin(this.params.SubscriptionID,
this.params.SubscriptionPassword,
this.params.BridgeID,this.params.UserID,
this.params.Password,this.params.BranchID,this.params.LangID)
.subscribe(login=>{
console.log(login);
});
}}
Thats my whole codeâŚ
its a bit different to yours