Click here to Skip to main content
14,574,365 members
   

ASP.NET

 
PinnedHOW TO ANSWER A QUESTION PinPopular
Chris Maunder12-Jul-09 22:39
cofounderChris Maunder12-Jul-09 22:39 
PinnedHow to get an answer to your question Pin
Chris Maunder10-Nov-05 16:29
cofounderChris Maunder10-Nov-05 16:29 
Questionpls help Pin
Member 148797913hrs 37mins ago
MemberMember 148797913hrs 37mins ago 
SuggestionRe: pls help Pin
Richard MacCutchan3hrs 33mins ago
mveRichard MacCutchan3hrs 33mins ago 
QuestionMessage Closed Pin
4hrs 31mins ago
Memberexplor56434hrs 31mins ago 
QuestionAngular service error http 400 using .Net core api to accept json, escaped quotes crashing api Pin
jkirkerx29-Jun-20 12:48
professionaljkirkerx29-Jun-20 12:48 
I spent all day on this. It just started happening recently.
So I package a model in Angular, and create a body of JSON using JSON.stringify(model)
Then package it all up and send it as a promise. I just noticed that the JSON quotes are escaped out with a slash, and it crashes the API. If I take the slashes out, the API accepts the JSON.

I'm not sure what to make of this, and if I should fix the client side or work on the server side with this.
I put the replace(/\/g, "") in below to test the theory that it's the slashes crashing the API. Now the API works, but I can't see this as a permanent fix.
validateTokenAsPromise(signIn: SignIn): Promise<SignIn> {
    const authUrl = this.baseUrl + "api/auth/AuthenticateAccount";
    const toSignIn = JSON.stringify(signIn).replace(/\\/g, "");    
    const httpOptions = {
      headers: new HttpHeaders({
        "Content-Type": "application/json",
        "Accept": "application/json"
      })
    };
    return this.http.post<SignIn>(authUrl, toSignIn, httpOptions).toPromise();
  }

I send it to a .Net Core controller api, and the api rejects the call, because of the data in the body.
The data has the quotes escaped out.
[Produces("application/json")]
[Route("api/[controller]")]
[ApiController]

[HttpPost("AuthenticateAccount")]
public async Task<SignIn> AuthenticateAccount([FromBody] SignIn authParam)
{

Sending this data to the API, normally it just sends raw, but I wrote a special service to handle Google SignIn and Googles gapi and gapi.auth2. I can't see how this special API" would encode the JSON.
{\"Id\":\"114251204162343478403\",\"FirstName\":\"John\",\"LastName\":\"Smith\",\"AccountName\":\"jsmith@hackme.com\",\"Password\":\"2H3HY4ZwE8Sb5Ajz\",\"Token\":\"eyJhbGciOiJIUsdadasdasd1lIjoiSmltIiwiZW1haWwiOiJqa2lya2VyeEBnbWFpbC5jb20iLCJuYmYiOjE1OTM0NjkwMDYsImV4cCI6MTU5MzY0MTgwNiwiaWF0IjoxNTkzNDY5MDA2LCJpc3MiOiJodHRwczovL2xvY2FsaG9zdDo1MDAxLyIsImF1ZCI6asdsadasdasdasdwMS9hcGkifQ.WdpYg8qDIUtIT4uobyAWVQ01k9iNYJ6wPpa6FIXm3Yg\",\"Role\":\"Customer\",\"ExpiresAt\":\"2020-06-29T23:26:03.812Z\",\"IdpId\":\"gapi\",\"RememberMe\":true,\"Avatar\":{\"Url\":\"https://lh3.googleusercontent.com/a-/AOasdasdasdGJB_aUO-asdasdasdg-ob=s96-c\"}}

Don't get excited about the data, it's fake.
If it ain't broke don't fix it
Discover my world at jkirkerx.com

AnswerRe: Angular service error http 400 using .Net core api to accept json, escaped quotes crashing api Pin
Richard Deeming29-Jun-20 23:42
mveRichard Deeming29-Jun-20 23:42 
GeneralRe: Angular service error http 400 using .Net core api to accept json, escaped quotes crashing api Pin
jkirkerx30-Jun-20 6:06
professionaljkirkerx30-Jun-20 6:06 
Questionerror server Pin
Member 1265427722-Jun-20 2:37
MemberMember 1265427722-Jun-20 2:37 
AnswerRe: error server Pin
ZurdoDev22-Jun-20 2:44
mveZurdoDev22-Jun-20 2:44 
AnswerRe: error server Pin
Richard Deeming22-Jun-20 5:19
mveRichard Deeming22-Jun-20 5:19 
GeneralRe: error server Pin
Member 1265427722-Jun-20 23:37
MemberMember 1265427722-Jun-20 23:37 
AnswerRe: error server Pin
Member 1265427722-Jun-20 23:41
MemberMember 1265427722-Jun-20 23:41 
AnswerRe: error server Pin
OriginalGriff22-Jun-20 23:51
mveOriginalGriff22-Jun-20 23:51 
GeneralRe: error server Pin
Member 1265427723-Jun-20 1:34
MemberMember 1265427723-Jun-20 1:34 
AnswerRe: error server Pin
OriginalGriff22-Jun-20 23:43
mveOriginalGriff22-Jun-20 23:43 
QuestionAnother NetCore question Pin
pkfox31-May-20 4:58
professionalpkfox31-May-20 4:58 
AnswerRe: Another NetCore question Pin
Mycroft Holmes31-May-20 12:22
professionalMycroft Holmes31-May-20 12:22 
GeneralRe: Another NetCore question Pin
pkfox1-Jun-20 1:58
professionalpkfox1-Jun-20 1:58 
GeneralRe: Another NetCore question Pin
Mycroft Holmes1-Jun-20 12:44
professionalMycroft Holmes1-Jun-20 12:44 
AnswerRe: Another NetCore question Pin
Richard Deeming1-Jun-20 3:31
mveRichard Deeming1-Jun-20 3:31 
GeneralRe: Another NetCore question Pin
pkfox1-Jun-20 4:08
professionalpkfox1-Jun-20 4:08 
AnswerRe: Another NetCore question Pin
jkirkerx1-Jun-20 13:47
professionaljkirkerx1-Jun-20 13:47 
GeneralRe: Another NetCore question Pin
pkfox4-Jun-20 10:54
professionalpkfox4-Jun-20 10:54 
QuestionCheckboxList Styling Problem Pin
feelblue8730-May-20 6:14
Memberfeelblue8730-May-20 6:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.