how to post formdata or http.context.form data from angular 6 to asp.net mvc web api or api using Token based authentication with header
_____________________________________________________________________
Create form data :-
const formdata = new FormData();
formdata.append('postJson', JSON.stringify(postJson));
_____________________________________________________________________
Attach Form data To Form-data object and call contract service to post data :-
this.PostService.Postdata(formdata).then((res: any) => {
this.loggerService.info(res.status);
this.responseStatus = res.status;
this.responseDraftId = res.result.alfResponse.draftId;
if (res.status === 200) {
this.responseFilePath = res.result ? (res.result.FullFilePath ? res.result.FullFilePath : '') : '';
this.showPopup('success', 'Success!', res.result.Reference + ' File has been created successfully.');
} else {
this.showPopup('error', 'Error!', 'Error while submit Contract!');
}
}).catch(error => {
this.loggerService.error(error);
this.showPopup('error', 'Error!', 'Error while submit Contract!');
});
}
______________________________________________________________________________
create Service "Post Service" with Promises :-
PostService(data: any): Promise<any> {
return new Promise((resolve, reject) => {
this.apiService.postWithformHeader('Contract/GenerateContract', data).subscribe((res: any) => {
return resolve(res);
}, (err) => {
reject(err);
});
});
}
//note apiservice is class name where this method is write
_________________________________________________________________________________
method for form data header Attach with Token :-
postWithformHeader(URL, data) {
this.spinner.displaySpinner(true);
const optionsData: any;
if(localstorage.getkey('mytoken'))
{
optionsData = {
headers: this.createAuthorizationHeader(),
};
}
else{
this.router.navigate(['login']);
}
const response = this.http.post(this.appUrl + URL, data,optionsData).map((res => {
this.spinner.displaySpinner(false);
return res;
})).catch((error: any) => {
this.spinner.displaySpinner(false);
return this.httpErrorHandler.handleError('api-service', error, URL);
});
return response;
}
_________________________________________________________________________________
Method for create header :-
createAuthorizationHeader() {
let headers = new HttpHeaders();
headers = headers.append('authorization', 'Bearer ' + localstorage.getkey('mytoken'));
return headers;
}
________________________________________________________________________________
Thanks for this kind of worthy information. this was really very helpful to me. keep continuing.
ReplyDeleteEducation Franchise India
Spoken English Franchise
Franchise For Spoken English Classes
Top Education Franchise In India
Best Education Franchise In India
Computer Education Franchise
Education Franchise India
Computer Center Franchise
Education Franchise Opportunities In India
adana escort - adıyaman escort - afyon escort - aksaray escort - antalya escort - aydın escort - balıkesir escort - batman escort - bitlis escort - burdur escort - bursa escort - diyarbakır escort - edirne escort - erzurum escort - eskişehir escort - eskişehir escort - eskişehir escort - eskişehir escort - gaziantep escort - gebze escort - giresun escort - hatay escort - ısparta escort - karabük escort - kastamonu escort - kayseri escort - kilis escort - kocaeli escort - konya escort - kütahya escort - malatya escort - manisa escort - maraş escort - mardin escort - mersin escort - muğla escort - niğde escort - ordu escort - osmaniye escort - sakarya escort - samsun escort - siirt escort - sincan escort - tekirdağ escort - tokat escort - uşak escort - van escort - yalova escort - yozgat escort - urfa escort - zonguldak escort
ReplyDeletecami avizesi - cami avizeleri - avize cami - no deposit bonus forex 2021 - takipçi satın al - takipçi satın al - takipçi satın al - takipcialdim.com/tiktok-takipci-satin-al/ - instagram beğeni satın al - instagram beğeni satın al - btcturk - tiktok izlenme satın al - sms onay - youtube izlenme satın al - no deposit bonus forex 2021 - tiktok jeton hilesi - tiktok beğeni satın al - binance - takipçi satın al - uc satın al - sms onay - sms onay - tiktok takipçi satın al - tiktok beğeni satın al - twitter takipçi satın al - trend topic satın al - youtube abone satın al - instagram beğeni satın al - tiktok beğeni satın al - twitter takipçi satın al - trend topic satın al - youtube abone satın al - takipcialdim.com/instagram-begeni-satin-al/ - tiktok takipçi satın al - tiktok beğeni satın al - twitter takipçi satın al - trend topic satın al - youtube abone satın al - instagram beğeni satın al - perde modelleri - instagram takipçi satın al - takipçi satın al - instagram takipçi satın al - betboo
ReplyDeleteYou should be a piece of a challenge for probably the best website on the web. I will suggest this site!
ReplyDeletetech news
aşk kitapları
ReplyDeleteyoutube abone satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipcialdim.com/tiktok-takipci-satin-al/
instagram beğeni satın al
beğeni satın al
btcturk
tiktok izlenme satın al
sms onay
youtube izlenme satın al
tiktok jeton hilesi
tiktok beğeni satın al
takipçi satın al
uc satın al
sms onay
sms onay
tiktok takipçi satın al
tiktok beğeni satın al
twitter takipçi satın al
trend topic satın al
youtube abone satın al
instagram beğeni satın al
tiktok beğeni satın al
twitter takipçi satın al
trend topic satın al
youtube abone satın al
takipcialdim.com/instagram-begeni-satin-al/
perde modelleri
instagram takipçi satın al
instagram takipçi satın al
takipçi satın al
instagram takipçi satın al
betboo
marsbahis
sultanbet
takipçi satın al
ReplyDeleteinstagram takipçi satın al
https://www.takipcikenti.com
marsbahis
ReplyDeletebetboo
sultanbet
marsbahis
betboo
sultanbet
bitcoin nasıl alınır
ReplyDeletetiktok jeton hilesi
youtube abone satın al
gate io güvenilir mi
referans kimliği nedir
tiktok takipçi satın al
bitcoin nasıl alınır
mobil ödeme bozdurma
mobil ödeme bozdurma
Fanatics.This is an amazing website, I really enjoyed your articles. apply Turkey e visa from India is a very simple process. You can apply for a Turkish visa from anywhere and any time. This facility is available for 24*7.
ReplyDeletebeykoz alarko carrier klima servisi
ReplyDeletekadıköy lg klima servisi
beykoz vestel klima servisi
tuzla arçelik klima servisi
üsküdar beko klima servisi
pendik alarko carrier klima servisi
tuzla toshiba klima servisi
çekmeköy vestel klima servisi
ataşehir vestel klima servisi
Good content. You write beautiful things.
ReplyDeletesportsbet
korsan taksi
mrbahis
vbet
vbet
taksi
sportsbet
mrbahis
hacklink
Great Post, keep posting more valuable information Java Training In Pune
ReplyDelete