B
B
brusk0012019-08-21 12:54:49
Vue.js
brusk001, 2019-08-21 12:54:49

Why can't I send a POST request with axios or vue-resource?

Good afternoon. Can't send post request via vue-resource or axios, in both cases error : Access to XMLHttpRequest at ' https://api.bitaps.com/btc/v1/create/payment/address ' from origin ' localhost:8080 ' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
Found info about headers
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PATCH, PUT, DELETE, OPTIONS',
'Access-Control-Allow-Headers' ': 'Origin, Content-Type, X-Auth-Token'
but still the same error.
Component Code

<template>
    <div class="container">
        <div class="row">
            <div class="col text-center mt-5">
                <button class="btn btn-lg btn-success" type="button" v-on:click="getBtcAddress">Get Btc</button>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    data() {
        return {
            forwarding_address: '18Hh2hEY8cV4mk9dQwjzyjkEzrUgMY71Kv',
            callback_link: 'http://www.2qgsl7gnaiiypmda.onion/handler',
            confirmations: 2
        }
    },
    methods: {
        getBtcAddress: function() {
            const options = {
                headers: {    
                    'Access-Control-Allow-Origin': '*',
                    'Access-Control-Allow-Methods': 'GET, POST, PATCH, PUT, DELETE, OPTIONS',
                    'Access-Control-Allow-Headers': 'Origin, Content-Type, X-Auth-Token'
                }
            }
            this.axios.post('https://api.bitaps.com/btc/v1/create/payment/address', {forwarding_address: this.forwarding_address, callback_link: this.callback_link, confirmations: this.confirmations}, options).then((response) => {
                console.log(response.data)
            })
        }
    }
}
</script>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
brusk001, 2019-08-21
@brusk001

There is an option to kill CORS in chrome (open -n -a "Google Chrome" --args --user-data-dir=/tmp/temp_chrome_user_data_dir localhost:8100 --disable-web-security), everything works, but it's like- it is not humane, and it is not clear whether it will work in production.

I
Ihor Bratukh, 2019-08-21
@BRAGA96

These headers must be on the server where you are sending the request and not on the client. Or proxy the request through your server or look at the api docs, maybe some kind of token is needed there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question