Home > Blockchain >  How to avoid the field changing in Postman?
How to avoid the field changing in Postman?

Time:08-24

I'm trying to make HTTP requests to a Netsuite server and I'm using Postman to test them. Then I'm using the JavaScript code generated by Postman in VSCode and it works only the first time. If I want to make another test, I have to send it first from Postman and then copy-paste the code to VSCode again, because some fields of the 'Authorization' parameter change every time a request is sent. Is there a way to avoid this? Or should I do something different in VSCode? These are the parameters I'm using in VSCode:

'Authorization':'OAuth realm="",
                 oauth_consumer_key="",
                 oauth_token="",
                 oauth_signature_method="",
                 oauth_timestamp="",
                 oauth_nonce="",
                 oauth_version=""
                 oauth_signature=""',
'Cookie': ''

The ones that always change are oauth_timestamp, oauth_nonce, oauth_signature. Here's the complete code:

var axios = require('axios');

var config = {
    method: 'get',
    url: 'https://url',
    headers: {
        'Authorization':'OAuth realm="",
                     oauth_consumer_key="",
                     oauth_token="",
                     oauth_signature_method="",
                     oauth_timestamp="",
                     oauth_nonce="",
                     oauth_version=""
                     oauth_signature=""',
    'Cookie': ''
    }
};

axios(config)
    .then(function (response) {
        console.log(JSON.stringify(response.data));
    })
    .catch(function (error) {
        console.log(error);
    });

CodePudding user response:

try with async function: something like this:

async function(){

            try {
                const userToken = await AsyncStorage.getItem('userToken');
                let {data} = await axios.get("http://104.248.125.152:1337/api/tasks-category/format",{
                    headers:{
                        Authorization: `Bearer ${userToken}`
                    }
                })
                if (data) {
                    let info = data.data
                    setTasks(info)
                }
                
            } catch (error) {
                console.log(error)
            }
        }
  • Related