You need to sign in to do that
Don't have an account?
sevindu
how to pass query parameters in HttpRequest?
I am currently using following method to get authorization code
############################
public PageReference sync(){
settings = ConstantContactSettings.getData();
PageReference ref = new PageReference(ConstantContactConstants.AUTH_ENDPOINT+
'client_id='+settings.ClientID__c+
'&redirect_uri='+settings.Redirect_URL__c+
'&scope='+ConstantContactConstants.SCOPE+
'&response_type='+ConstantContactConstants.RESPONSE_TYPE);
return ref;
}
#######################
Issue is it refreshes the page. How can I use HttpGet Callout instead of this approach and how to add query parameters to endpoint URL?
############################
public PageReference sync(){
settings = ConstantContactSettings.getData();
PageReference ref = new PageReference(ConstantContactConstants.AUTH_ENDPOINT+
'client_id='+settings.ClientID__c+
'&redirect_uri='+settings.Redirect_URL__c+
'&scope='+ConstantContactConstants.SCOPE+
'&response_type='+ConstantContactConstants.RESPONSE_TYPE);
return ref;
}
#######################
Issue is it refreshes the page. How can I use HttpGet Callout instead of this approach and how to add query parameters to endpoint URL?
More click here (https://tattoodi.com/tiger-tattoos/)
you can use below code:-
if you fond this useful then, PLEASE MARK AS A BEST ANSWER!!
Please refer these links, maybe it will help you
For HttpRequest Class:-
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_http_httprequest.htm
For Invoking HTTP Callouts :-
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_callouts_http.htm
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
According to other links:
You can configure it by importing the HTTP client module from the @angular/common/HTTP package.
import {HttpClientModule} from '@angular/common/http';
@NgModule({
imports: [ BrowserModule, HttpClientModule ],
declarations: [ App ],
bootstrap: [ App ]
})
export class AppModule {}
After that you can inject the HttpClient and use it to do the request.
import {HttpClient} from '@angular/common/http'
@Component({
selector: 'my-app',
template: `
<div>
<h2>Hello {{name}}</h2>
</div>
`,
})
export class App {
name:string;
constructor(private httpClient: HttpClient) {
this.httpClient.get('/url', {
params: {
appid: 'id1234',
cnt: '5'
},
observe: 'response'
})
.toPromise()
.then(response => {
console.log(response);
})
.catch(console.log);
}
}
For angular versions prior to version 4 you can do the same using the Http service.
The Http.get method takes an object that implements RequestOptionsArgs as a second parameter.
The search field of that object can be used to set a string or a URLSearchParams object.
An example:
// Parameters obj-
let params: URLSearchParams = new URLSearchParams();
params.set('appid', StaticSettings.API_KEY);
params.set('cnt', days.toString());
//Http request-
return this.http.get(StaticSettings.BASE_URL, {
search: params
}).subscribe(
(response) => this.onGetForecastResult(response.json()),
(error) => this.onGetForecastError(error.json()),
() => this.onGetForecastComplete()
);
The documentation for the Http class has more details. It can be found here and an working example here.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi