0

Able to get the response in postman. But unable to get in axios. Getting html as response. What would be the problem?

import axios from 'react-native-axios';

var config = {
  headers: {
    'Content-Type': 'Application/Json',
    'JsonStub-User-Key': '__USER__KEY',
    'JsonStub-Project-Key': '__PROJECT__KEY'
  }
};

export async function menuListByCategories() {
  // simulate an asynchronous operation
  const url = "http://jsonstub.com/burgers";
  axios.get(url, {config})
    .then((response) = > {
      console.log(response.data);
    })
    .
  catch ((error) = > {
    console.log("axios error:", error);
  });
}

Update: check the response of this code

4
  • Do you get any error response like 404, 500 or something like that? Commented Nov 5, 2017 at 12:06
  • @IzumiSy getting 200 as response. and its in html format. Not in json Commented Nov 5, 2017 at 12:09
  • But you cannot get 200 response with axios, right? Then, what do you get? Commented Nov 5, 2017 at 12:15
  • check the SS of the response. Commented Nov 5, 2017 at 12:19

1 Answer 1

1

You can add data: {} in config in order not to have Content-Type removed by axios. Check the answer of the question below.

Jsonstub response not showing

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

8 Comments

Thanks for the link. Tried but not working. we can't set data for a GET request, and at the same time, the "Content-Type" header for a request without data gets ignored. How can I handle?
How about changing {config} just to config and trying it again?
Ya. If I change into that, I get status as 403.
You are getting one step closer. 403 means "Forbidden" so that I think your API keys might not correct to call API. Could you check them out?
creds are correct. I'm getting JSON data in postman. If I use {config}, then status is 200 OK and its in html response. I want it in json. But unable to get it.
|

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.