Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use headers? #2

Closed
hateCarrot opened this issue Dec 1, 2016 · 8 comments
Closed

How to use headers? #2

hateCarrot opened this issue Dec 1, 2016 · 8 comments

Comments

@hateCarrot
Copy link

hateCarrot commented Dec 1, 2016

Hi.

This error occurs when using headers.
bundle.js:9485 Warning: Failed prop type: Invalid prop headers of type string supplied to Request, expected object.

and I used headers as shown below.
headers='{"Authorization":"ApiKey api_key=blah blah"}'

What is the problem?
Thanks.

@mbasso
Copy link
Owner

mbasso commented Dec 1, 2016

Hi @hateCarrot,
have you tried the following?
headers={{"Authorization":"ApiKey api_key=blah blah"}}

@hateCarrot
Copy link
Author

hi @mbasso
I changed it to the way you told me. Then the error message was changed.

"XMLHttpRequest cannot load http://konanlink-test.elasticbeanstalk.com/v1/device/list.json. Request header field Authorization is not allowed by Access-Control-Allow-Headers in preflight response."

The above address is normally returned when running as postman. So it does not seem to be a server problem. Do I have something more to do? Thank you for your reply.

@hateCarrot
Copy link
Author

hateCarrot commented Dec 2, 2016

and Here is request code.

<Request
  url='http://konanlink-test.elasticbeanstalk.com/v1/device/list.json'
  method='post'
  type='application/x-www-form-urlencoded'
  accept='application/json'
  headers={{"Authorization":"ApiKey api_key=blah blah"}}
  verbose={true}
  send='{"offset":"0","limit":"100"}'
>
  {
    ({error, result, loading}) => {
      if (loading) {
        return <div>loading...</div>;
      } else {
        return <div>{ JSON.stringify(result) }</div>;
      }
    }
  }
</Request>

@mbasso
Copy link
Owner

mbasso commented Dec 2, 2016

Unfortunately it seems to be a server problem.
Postman works fine because is a chrome extension and has more privileges than regular web pages (check this for more information).
However, to make your site work, you have to enable CORS.
Here you can find a simple explanation of the problem is and here is an example of the headers that you have to add to the reponse.

@hateCarrot
Copy link
Author

Thanks a lot @mbasso
I'll try to solve the problem as you told me.
Merry Christmas and Happy new year :)

@mbasso
Copy link
Owner

mbasso commented Dec 10, 2016

Thanks, you too :) 🎄 🎅
Did you solve the problem with CORS?

@mbasso
Copy link
Owner

mbasso commented Dec 19, 2016

@hateCarrot Can I close this issue?

@hateCarrot
Copy link
Author

I'm sorry I was late. Thank you for your great help. Close this issue.
Merry Christmas & Happy new year :)

@mbasso mbasso closed this as completed Dec 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants