“Status Code:200 OK (from ServiceWorker)” in Chrome Network DevTools?

This is a common source of confusion, so I wanted to go into a bit more detail. I have a full working demo in this Gist, and you can view a live version of it thanks to RawGit. Here’s the relevant portion of the service worker code inline, for illustrative purposes: self.addEventListener(‘fetch’, event => { … Read more

CORS error :Request header field Authorization is not allowed by Access-Control-Allow-Headers in preflight response

This is an API issue, you won’t get this error if using Postman/Fielder to send HTTP requests to API. In case of browsers, for security purpose, they always send OPTIONS request/preflight to API before sending the actual requests (GET/POST/PUT/DELETE). Therefore, in case, the request method is OPTION, not only you need to add “Authorization” into … Read more

Set up an HTTP proxy to insert a header

I do something like this in my development environment by configuring Apache on port 80 as a proxy for my application server on port 8080, with the following Apache config: NameVirtualHost * <VirtualHost *> <Proxy http://127.0.0.1:8080/*> Allow from all </Proxy> <LocationMatch “/myapp”> ProxyPass http://127.0.0.1:8080/myapp ProxyPassReverse http://127.0.0.1:8080/myapp Header add myheader “myvalue” RequestHeader set myheader “myvalue” </LocationMatch> … Read more

Passing headers and query params in HTTparty

Use Strings for your hash keys instead of Symbols. query = { “method” => “neworder”, “nonce” => 1404996028, “order_type” => “buy”, “quantity” => 1, “rate” => 1 } headers = { “key” => “8781974720909019987”, “sign” => “0a3888ac7f8e411ad73a0a503c55db70a291bfb9f9a47147d5200882674f717f6ede475669f3453” } HTTParty.post( “https://www.acb.com/api/v2/market/LTC_BTC/”, :query => query, :headers => headers ) It was probably only the headers that were … Read more

HTTP HEAD Request in Javascript/Ajax?

Easy, just use the HEAD method, instead of GET or POST: function UrlExists(url, callback) { var http = new XMLHttpRequest(); http.open(‘HEAD’, url); http.onreadystatechange = function() { if (this.readyState == this.DONE) { callback(this.status != 404); } }; http.send(); } This is just a short example to show how to use the HEAD method. Production code may … Read more

Allow All Content Security Policy?

For people who still want an even more permissive posts, because the other answers were just not permissive enough, and they must work with google chrome for which * is just not enough: default-src * data: blob: filesystem: about: ws: wss: ‘unsafe-inline’ ‘unsafe-eval’ ‘unsafe-dynamic’; script-src * data: blob: ‘unsafe-inline’ ‘unsafe-eval’; connect-src * data: blob: ‘unsafe-inline’; … Read more

Set UserAgent in http request

When creating your request use request.Header.Set(“key”, “value”): package main import ( “io” “log” “net/http” ) func main() { client := &http.Client{} req, err := http.NewRequest(“GET”, “http://httpbin.org/user-agent”, nil) if err != nil { log.Fatalln(err) } req.Header.Set(“User-Agent”, “Golang_Spider_Bot/3.0”) resp, err := client.Do(req) if err != nil { log.Fatalln(err) } defer resp.Body.Close() body, err := io.ReadAll(resp.Body) if err … Read more

Using Axios GET with Authorization Header in React-Native App

For anyone else that comes across this post and might find it useful… There is actually nothing wrong with my code. I made the mistake of requesting client_credentials type access code instead of password access code (#facepalms). FYI I am using urlencoded post hence the use of querystring.. So for those that may be looking … Read more