Windows 10本地XAMPP环境下如何正确提交HERE API POST定位请求?
Fixing HERE Positioning API Errors in Local XAMPP Development
Alright, let's tackle these two issues you're facing with the HERE Positioning API in your Windows 10 + XAMPP local setup (http://localhost:8003/myFolder/):
1. First Error: POST https://pos.ls.hereapi.com/positioning/v1/locate... net::ERR_ABORTED 400 (Bad Request)
A 400 Bad Request means the API is rejecting your request due to invalid formatting, missing data, or incorrect parameters. Here's what to check:
- Validate your API Key: Double-check that your
apiKeyis active, has permissions for the Positioning API, and isn't truncated (your snippet showsLxj-xbibfpSHLMw1U...blabla—make sure the full, unmodified key is included). - Check Request Body Format: The
/positioning/v1/locateendpoint requires a specific JSON body with positioning data (like WiFi access points, cell towers, or GPS coordinates). A valid WiFi-based request example:{ "wifiAccessPoints": [ { "macAddress": "AA:BB:CC:DD:EE:FF", "signalStrength": -65, "age": 0 } ] } - Verify Request Headers: Ensure you're sending the correct
Content-Typeheader—HERE specifiesapplication/vnd.here.layerObjectList+json; charset=utf-8for this endpoint. Missing or mismatched headers will trigger a 400 error. - Check URL Parameters: Confirm there are no typos in the API endpoint URL, and the
apiKeyis properly appended as a query parameter.
2. Second Error: POST http://host/path?CORSH=%7B%22Content-Type%22... net::ERR_NAME_NOT_RESOLVED
This error has two clear fixes—let's break them down:
- Replace the Invalid Placeholder URL:
http://host/pathis a dummy address; swap it with the real HERE API endpoint:https://pos.ls.hereapi.com/positioning/v1/locate - Stop Putting CORS Headers in the URL: CORS headers belong in the request headers, not as query parameters. This is causing malformed requests and unnecessary complexity. If you're using JavaScript
fetch, your code should look like this:fetch('https://pos.ls.hereapi.com/positioning/v1/locate?apiKey=YOUR_FULL_API_KEY', { method: 'POST', headers: { 'Content-Type': 'application/vnd.here.layerObjectList+json; charset=utf-8', 'Accept': 'application/json; charset=UTF-8', 'GroupId': 'FGx1AWaAzKOo0imNkLmf', 'AuthServiceId': 'here_app', 'Auth-Identifier': 'Ykv6MmZ03OJtiFD4R7Ht', 'Auth-Secret': 'AXqUNisVW46XJs9_pxuzOzneKlYPrY5X_blablabla' }, body: JSON.stringify(yourPositioningDataObject) }) - Local Dev CORS Workaround: If you still hit CORS errors (common when localhost calls external APIs), set up a reverse proxy in XAMPP's Apache config to avoid cross-domain issues. Add this to your
httpd.confor a virtual host file:
Then update your request URL to use the proxy:ProxyPass /here-proxy https://pos.ls.hereapi.com ProxyPassReverse /here-proxy https://pos.ls.hereapi.comhttp://localhost:8003/here-proxy/positioning/v1/locate?apiKey=YOUR_API_KEY—this makes the request appear same-origin to your local dev server.
内容的提问来源于stack exchange,提问作者Serbona Applications
相关产品推荐
相关产品推荐

