2

Trying to make a simple POST call but getting the error:

TypeError: Cannot read properties of undefined (reading 'length')
    at HttpHeaders.applyUpdate (http.mjs:222:27)
    at http.mjs:195:58
    at Array.forEach (<anonymous>)
    at HttpHeaders.init (http.mjs:195:33)
    at HttpHeaders.forEach (http.mjs:263:14)
    at Observable._subscribe (http.mjs:2116:29)
    at Observable._trySubscribe (Observable.js:37:25)
    at Observable.js:31:30
    at errorContext (errorContext.js:19:9)
    at Observable.subscribe (Observable.js:22:21)

I'm setting the base headers and making the post request:

let headers = new HttpHeaders({'Content-Type': 'application/x-www-form-urlencoded'});
    this.http.post(
      '<target domain>',
      {
        grant_type: '<grant_type>',
        code: '<code>',
        redirect_uri: '<redirect_uri>',
        client_id: '<client_id>'
      },
      {
        headers
      }
    ).subscribe({
      next: (response) => {
        console.log('Token response:', response);
      },
      error: (error) => {
        console.log('error:', error);
      }
    });

The headers variable is just the default new HttpHeaders values with Content-Type added. It seem like it should work as expected. Am I missing something?

4
  • issue in not happening in the code shared stackblitz reproduction, please replicate on the stackblitz and share back Commented Apr 16 at 14:20
  • please validate your interceptor that is where the error might be coming from Commented Apr 16 at 14:28
  • @NarenMurali actually, I forgot, we have a customer interceptor. That might be the issue! I'll double check it Commented Apr 16 at 14:59
  • 1
    @NarenMurali that was the issue. My interceptor injects additional headers for our company API calls. I'm getting a new error but it's unrelated. thanks! Commented Apr 16 at 15:35

1 Answer 1

0

The issue is not from the code shared, usually the API calls, will pass through an interceptor, so identify the problematic interceptor that might cause the error.

Reference Stackblitz

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.