简体   繁体   中英

CORS Issue when calling Walmart Open API

We are using Walmart Open APIs and getting CORS issue. For example, when attempting to call tending items API, we are getting the following response: (replacing API key, publisher ID and domain for security)

Access to XMLHttpRequest at ' https://api.walmartlabs.com/v1/trends?apiKey= {api_key}&amp&publisherId={publisher_id}&format=json' from origin ' https://example.com ' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

How do we whitelist our domain for cross origin? Please advise.

Attempted to call the Walmart open API from javascript code on our website. Not sure how to resolve CORS issue.

Was expecting to get back list of trending items from Walmart APIs.

Try using this piece of line in package.json
"proxy": "http://192.165.1.220:28080",

where this host and port will be of walmart and install "http-proxy-middleware" using npm and try again.

CORS: EXPLANATION Cross-Origin Resource Sharing (CORS) is a mechanism that uses additional HTTP headers to tell browsers to give a web application running at one origin, access to selected resources from a different origin. A web application executes a cross-origin HTTP request when it requests a resource that has a different origin (domain, protocol, or port) from its own. Means your localhost is trying to connect other domain so for security purpose it is blocking. You need to enable it for connecting to their IP.

For more clear and wider views: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM