I had this working months ago but now I can't figu...
# javascript
c
I had this working months ago but now I can't figure out how I did it for the life of me. I want to make a post request to a server i'm running on localhost using the fetch api. I can run Get requests with no troubles but the POST requests always fail, regardless of browser. I get a
TypeError: Failed to execute 'fetch' on 'Window': Invalid referrer policy
error every time. The server is set to allow cors for "*". My request looks like this:
Copy code
val requestOpts = RequestInit().apply {
    method = "POST"
    body = JSON.stringify(postData)
}

window.fetch("<http://localhost:7000>", requestOpts).then { console.log("Post success!" }.catch { console.log("Whomp whooooomp") }
s
@chadmorrow try with
referrerPolicy = ""
in RequestInit
c
That just about did the trick I think. The promise did come back successfully and the server received the data but I got this error in the console:
Copy code
Error parsing 'integrity' attribute ('null'). The hash algorithm must be one of 'sha256', 'sha384', or 'sha512', followed by a '-' character.
seems like there may just need to be better default values provided for the RequestInit
Yeah, passing an empty string in for integrity takes care of that and there are no more errors
awesome, thanks for the suggestion @samir
s
Yes, empty string solves it. np
I agree about the default values, needs some tweaking.
b
Could you please file an issue?
👍 1