Postman 'POST' request sucess but Angular 5 'Post' not working












0















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.










share|improve this question




















  • 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
















0















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.










share|improve this question




















  • 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














0












0








0








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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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














  • 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












2 Answers
2






active

oldest

votes


















1














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.






share|improve this answer


























  • 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



















0














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.






share|improve this answer























    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
    });


    }
    });














    draft saved

    draft discarded


















    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









    1














    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.






    share|improve this answer


























    • 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
















    1














    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.






    share|improve this answer


























    • 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














    1












    1








    1







    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.






    share|improve this answer















    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.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    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



















    • 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













    0














    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.






    share|improve this answer




























      0














      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.






      share|improve this answer


























        0












        0








        0







        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.






        share|improve this answer













        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Apr 3 '18 at 1:29









        Namindu SanchilaNamindu Sanchila

        61110




        61110






























            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Guess what letter conforming each word

            Port of Spain

            Run scheduled task as local user group (not BUILTIN)