I
I
Ingvar Von Bjork2021-03-07 23:13:38
Angular
Ingvar Von Bjork, 2021-03-07 23:13:38

Why does it return text/html instead of application/json?

I am sending a request like this:

const headers = new HttpHeaders({
      'Content-Type': 'application/json',
      Authorization: 'Bearer 3e5cac39-7e38-4139-8fd6-30adc06a61bd',
    });

    const body = {
      notifyUrl: 'https://your.eshop.com/notify',
      customerIp: '127.0.0.1',
      merchantPosId: '145227',
      description: 'RTV market',
      currencyCode: 'PLN',
      totalAmount: '21000',
      buyer: {
        email: '[email protected]',
        phone: '654111654',
        firstName: 'John',
        lastName: 'Doe',
        language: 'pl',
      },
      products: [
        {
          name: 'Wireless Mouse for Laptop',
          unitPrice: '15000',
          quantity: '1',
        },
        {
          name: 'HDMI cable',
          unitPrice: '6000',
          quantity: '1',
        },
      ],
    };

    return this.http
      .post('https://secure.payu.com/api/v2_1/orders', body, {
        headers: headers,
      })
      .subscribe((res) => {
        console.log(res);
      });

But in the console I get an error
f1tg3QL.png

Although I expect to get something like this json:
{  
   "status":{  
      "statusCode":"SUCCESS",
   },
   "redirectUri":"{payment_summary_redirection_url}",
   "orderId":"WZHF5FFDRJ140731GUEST000P01",
   "extOrderId":"{YOUR_EXT_ORDER_ID}",
}

If console.log is replaced with console.warn, then you can see HTML code that JSON.parse() cannot process.
What have I done wrong?

UPD
The link I need is returned to the url from the screen, but for some reason, instead of trying to parse the JSON response, it takes redirectURL and parses the page

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Daniil Vasilyev, 2021-03-08
@hello_my_name_is_dany

Try adding HTTP header
Accept: application/json

A
Anton Shvets, 2021-03-08
@Xuxicheta

This is a question to the server why it returns html. Understand networking.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question