Postman 'POST' request sucess but Angular 5 'Post' not working
I am trying to insert a data object via web API to the database. when I using the Postmen, POST request is the success. but in angular 5 app post request indicates 500 Internal saver error. here is my source code.
player.service.ts
@Injectable()
export class PlayerService {
private _postPlayer = 'http://192.168.8.101/api/Values/insertData';
constructor(private _http: HttpClient) { }
httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
})
};
// save the new player
save(palyer: Player): Observable<Player> {
console.log(palyer.playingRole);
return this._http.post<Player>(this._postPlayer, palyer, this.httpOptions)
}
}
here are my Components
export class AddplayerComponent implements OnInit {
player: Player = new Player();
playerAdd: FormGroup;
players: Player;
constructor(private plService: PlayerService) { }
ngOnInit() {
this.playerAdd = new FormGroup(
{
firstName: new FormControl(),
lastName: new FormControl(),
nickName: new FormControl(),
birthday: new FormControl(),
playingRole: new FormControl(),
battingStyle: new FormControl(),
bowllingStyle: new FormControl(),
mobileNumber: new FormControl(),
email: new FormControl()
}
);
}
save() {
console.log(this.playerAdd.value);
this.player = this.playerAdd.value;
this.plService.save(this.player)
.subscribe();
}
}
Here are my ASP.NET WebApi Post
[HttpPost]
public void insertData([FormBody] Player Ob){
// to connect EF6 context
}
Get request is working fine. but Post request is not working.
angular
|
show 1 more comment
I am trying to insert a data object via web API to the database. when I using the Postmen, POST request is the success. but in angular 5 app post request indicates 500 Internal saver error. here is my source code.
player.service.ts
@Injectable()
export class PlayerService {
private _postPlayer = 'http://192.168.8.101/api/Values/insertData';
constructor(private _http: HttpClient) { }
httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
})
};
// save the new player
save(palyer: Player): Observable<Player> {
console.log(palyer.playingRole);
return this._http.post<Player>(this._postPlayer, palyer, this.httpOptions)
}
}
here are my Components
export class AddplayerComponent implements OnInit {
player: Player = new Player();
playerAdd: FormGroup;
players: Player;
constructor(private plService: PlayerService) { }
ngOnInit() {
this.playerAdd = new FormGroup(
{
firstName: new FormControl(),
lastName: new FormControl(),
nickName: new FormControl(),
birthday: new FormControl(),
playingRole: new FormControl(),
battingStyle: new FormControl(),
bowllingStyle: new FormControl(),
mobileNumber: new FormControl(),
email: new FormControl()
}
);
}
save() {
console.log(this.playerAdd.value);
this.player = this.playerAdd.value;
this.plService.save(this.player)
.subscribe();
}
}
Here are my ASP.NET WebApi Post
[HttpPost]
public void insertData([FormBody] Player Ob){
// to connect EF6 context
}
Get request is working fine. but Post request is not working.
angular
1
It means your API has some issue, chekc if there is an error thrown
– Sajeetharan
Mar 18 '18 at 3:41
So, why postman POST working?
– Namindu Sanchila
Mar 18 '18 at 3:42
1
so that means the data you sent from angular is not valid
– Sajeetharan
Mar 18 '18 at 3:43
1
check this:github.com/angular/angular/issues/19535
– i_th
Mar 18 '18 at 3:43
Can you share the server side error, please?
– sn42
Mar 18 '18 at 3:59
|
show 1 more comment
I am trying to insert a data object via web API to the database. when I using the Postmen, POST request is the success. but in angular 5 app post request indicates 500 Internal saver error. here is my source code.
player.service.ts
@Injectable()
export class PlayerService {
private _postPlayer = 'http://192.168.8.101/api/Values/insertData';
constructor(private _http: HttpClient) { }
httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
})
};
// save the new player
save(palyer: Player): Observable<Player> {
console.log(palyer.playingRole);
return this._http.post<Player>(this._postPlayer, palyer, this.httpOptions)
}
}
here are my Components
export class AddplayerComponent implements OnInit {
player: Player = new Player();
playerAdd: FormGroup;
players: Player;
constructor(private plService: PlayerService) { }
ngOnInit() {
this.playerAdd = new FormGroup(
{
firstName: new FormControl(),
lastName: new FormControl(),
nickName: new FormControl(),
birthday: new FormControl(),
playingRole: new FormControl(),
battingStyle: new FormControl(),
bowllingStyle: new FormControl(),
mobileNumber: new FormControl(),
email: new FormControl()
}
);
}
save() {
console.log(this.playerAdd.value);
this.player = this.playerAdd.value;
this.plService.save(this.player)
.subscribe();
}
}
Here are my ASP.NET WebApi Post
[HttpPost]
public void insertData([FormBody] Player Ob){
// to connect EF6 context
}
Get request is working fine. but Post request is not working.
angular
I am trying to insert a data object via web API to the database. when I using the Postmen, POST request is the success. but in angular 5 app post request indicates 500 Internal saver error. here is my source code.
player.service.ts
@Injectable()
export class PlayerService {
private _postPlayer = 'http://192.168.8.101/api/Values/insertData';
constructor(private _http: HttpClient) { }
httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
})
};
// save the new player
save(palyer: Player): Observable<Player> {
console.log(palyer.playingRole);
return this._http.post<Player>(this._postPlayer, palyer, this.httpOptions)
}
}
here are my Components
export class AddplayerComponent implements OnInit {
player: Player = new Player();
playerAdd: FormGroup;
players: Player;
constructor(private plService: PlayerService) { }
ngOnInit() {
this.playerAdd = new FormGroup(
{
firstName: new FormControl(),
lastName: new FormControl(),
nickName: new FormControl(),
birthday: new FormControl(),
playingRole: new FormControl(),
battingStyle: new FormControl(),
bowllingStyle: new FormControl(),
mobileNumber: new FormControl(),
email: new FormControl()
}
);
}
save() {
console.log(this.playerAdd.value);
this.player = this.playerAdd.value;
this.plService.save(this.player)
.subscribe();
}
}
Here are my ASP.NET WebApi Post
[HttpPost]
public void insertData([FormBody] Player Ob){
// to connect EF6 context
}
Get request is working fine. but Post request is not working.
angular
angular
edited Mar 18 '18 at 3:47
Namindu Sanchila
asked Mar 18 '18 at 3:38
Namindu SanchilaNamindu Sanchila
61110
61110
1
It means your API has some issue, chekc if there is an error thrown
– Sajeetharan
Mar 18 '18 at 3:41
So, why postman POST working?
– Namindu Sanchila
Mar 18 '18 at 3:42
1
so that means the data you sent from angular is not valid
– Sajeetharan
Mar 18 '18 at 3:43
1
check this:github.com/angular/angular/issues/19535
– i_th
Mar 18 '18 at 3:43
Can you share the server side error, please?
– sn42
Mar 18 '18 at 3:59
|
show 1 more comment
1
It means your API has some issue, chekc if there is an error thrown
– Sajeetharan
Mar 18 '18 at 3:41
So, why postman POST working?
– Namindu Sanchila
Mar 18 '18 at 3:42
1
so that means the data you sent from angular is not valid
– Sajeetharan
Mar 18 '18 at 3:43
1
check this:github.com/angular/angular/issues/19535
– i_th
Mar 18 '18 at 3:43
Can you share the server side error, please?
– sn42
Mar 18 '18 at 3:59
1
1
It means your API has some issue, chekc if there is an error thrown
– Sajeetharan
Mar 18 '18 at 3:41
It means your API has some issue, chekc if there is an error thrown
– Sajeetharan
Mar 18 '18 at 3:41
So, why postman POST working?
– Namindu Sanchila
Mar 18 '18 at 3:42
So, why postman POST working?
– Namindu Sanchila
Mar 18 '18 at 3:42
1
1
so that means the data you sent from angular is not valid
– Sajeetharan
Mar 18 '18 at 3:43
so that means the data you sent from angular is not valid
– Sajeetharan
Mar 18 '18 at 3:43
1
1
check this:github.com/angular/angular/issues/19535
– i_th
Mar 18 '18 at 3:43
check this:github.com/angular/angular/issues/19535
– i_th
Mar 18 '18 at 3:43
Can you share the server side error, please?
– sn42
Mar 18 '18 at 3:59
Can you share the server side error, please?
– sn42
Mar 18 '18 at 3:59
|
show 1 more comment
2 Answers
2
active
oldest
votes
You need to stringify
your object:
return this._http.post<Player>(this._postPlayer, JSON.stringify(palyer), this.httpOptions)
And added the microsoft.aspnet.webapi.cors
package to the API.
Thank you. but I got the same error
– Namindu Sanchila
Mar 18 '18 at 3:57
oh thats strange! can you try to debug if you are getting the object on API
– Sajeetharan
Mar 18 '18 at 3:59
Thanks All. I prevent the bug. Its was my API. Sorry for all.
– Namindu Sanchila
Mar 18 '18 at 4:27
1
Thanks you again.I had miss this part also.
– Namindu Sanchila
Mar 18 '18 at 4:27
add a comment |
The error was I got here is not adding to the microsoft.aspnet.webapi.cors package to the API. just added it and its working fine. Thanks all for the support me.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f49344259%2fpostman-post-request-sucess-but-angular-5-post-not-working%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to stringify
your object:
return this._http.post<Player>(this._postPlayer, JSON.stringify(palyer), this.httpOptions)
And added the microsoft.aspnet.webapi.cors
package to the API.
Thank you. but I got the same error
– Namindu Sanchila
Mar 18 '18 at 3:57
oh thats strange! can you try to debug if you are getting the object on API
– Sajeetharan
Mar 18 '18 at 3:59
Thanks All. I prevent the bug. Its was my API. Sorry for all.
– Namindu Sanchila
Mar 18 '18 at 4:27
1
Thanks you again.I had miss this part also.
– Namindu Sanchila
Mar 18 '18 at 4:27
add a comment |
You need to stringify
your object:
return this._http.post<Player>(this._postPlayer, JSON.stringify(palyer), this.httpOptions)
And added the microsoft.aspnet.webapi.cors
package to the API.
Thank you. but I got the same error
– Namindu Sanchila
Mar 18 '18 at 3:57
oh thats strange! can you try to debug if you are getting the object on API
– Sajeetharan
Mar 18 '18 at 3:59
Thanks All. I prevent the bug. Its was my API. Sorry for all.
– Namindu Sanchila
Mar 18 '18 at 4:27
1
Thanks you again.I had miss this part also.
– Namindu Sanchila
Mar 18 '18 at 4:27
add a comment |
You need to stringify
your object:
return this._http.post<Player>(this._postPlayer, JSON.stringify(palyer), this.httpOptions)
And added the microsoft.aspnet.webapi.cors
package to the API.
You need to stringify
your object:
return this._http.post<Player>(this._postPlayer, JSON.stringify(palyer), this.httpOptions)
And added the microsoft.aspnet.webapi.cors
package to the API.
edited Nov 20 '18 at 4:18
fuzz
15.6k17109184
15.6k17109184
answered Mar 18 '18 at 3:54
SajeetharanSajeetharan
122k30173232
122k30173232
Thank you. but I got the same error
– Namindu Sanchila
Mar 18 '18 at 3:57
oh thats strange! can you try to debug if you are getting the object on API
– Sajeetharan
Mar 18 '18 at 3:59
Thanks All. I prevent the bug. Its was my API. Sorry for all.
– Namindu Sanchila
Mar 18 '18 at 4:27
1
Thanks you again.I had miss this part also.
– Namindu Sanchila
Mar 18 '18 at 4:27
add a comment |
Thank you. but I got the same error
– Namindu Sanchila
Mar 18 '18 at 3:57
oh thats strange! can you try to debug if you are getting the object on API
– Sajeetharan
Mar 18 '18 at 3:59
Thanks All. I prevent the bug. Its was my API. Sorry for all.
– Namindu Sanchila
Mar 18 '18 at 4:27
1
Thanks you again.I had miss this part also.
– Namindu Sanchila
Mar 18 '18 at 4:27
Thank you. but I got the same error
– Namindu Sanchila
Mar 18 '18 at 3:57
Thank you. but I got the same error
– Namindu Sanchila
Mar 18 '18 at 3:57
oh thats strange! can you try to debug if you are getting the object on API
– Sajeetharan
Mar 18 '18 at 3:59
oh thats strange! can you try to debug if you are getting the object on API
– Sajeetharan
Mar 18 '18 at 3:59
Thanks All. I prevent the bug. Its was my API. Sorry for all.
– Namindu Sanchila
Mar 18 '18 at 4:27
Thanks All. I prevent the bug. Its was my API. Sorry for all.
– Namindu Sanchila
Mar 18 '18 at 4:27
1
1
Thanks you again.I had miss this part also.
– Namindu Sanchila
Mar 18 '18 at 4:27
Thanks you again.I had miss this part also.
– Namindu Sanchila
Mar 18 '18 at 4:27
add a comment |
The error was I got here is not adding to the microsoft.aspnet.webapi.cors package to the API. just added it and its working fine. Thanks all for the support me.
add a comment |
The error was I got here is not adding to the microsoft.aspnet.webapi.cors package to the API. just added it and its working fine. Thanks all for the support me.
add a comment |
The error was I got here is not adding to the microsoft.aspnet.webapi.cors package to the API. just added it and its working fine. Thanks all for the support me.
The error was I got here is not adding to the microsoft.aspnet.webapi.cors package to the API. just added it and its working fine. Thanks all for the support me.
answered Apr 3 '18 at 1:29
Namindu SanchilaNamindu Sanchila
61110
61110
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f49344259%2fpostman-post-request-sucess-but-angular-5-post-not-working%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
It means your API has some issue, chekc if there is an error thrown
– Sajeetharan
Mar 18 '18 at 3:41
So, why postman POST working?
– Namindu Sanchila
Mar 18 '18 at 3:42
1
so that means the data you sent from angular is not valid
– Sajeetharan
Mar 18 '18 at 3:43
1
check this:github.com/angular/angular/issues/19535
– i_th
Mar 18 '18 at 3:43
Can you share the server side error, please?
– sn42
Mar 18 '18 at 3:59