Perform curl request in javascript?

后端 未结 3 1021
谎友^
谎友^ 2020-12-02 09:56

Is it possible to send a curl request in jQuery or javascript?

Something like this:

curl \\
-H \'Authorization: Bearer 6Q************\' \\
\'https:/         


        
3条回答
  •  庸人自扰
    2020-12-02 10:24

    You can use JavaScripts Fetch API (available in your browser) to make network requests.

    If using node, you will need to install the node-fetch package.

    const url = "https://api.wit.ai/message?v=20140826&q=";
    
    const options = {
      headers: {
        Authorization: "Bearer 6Q************"
      }
    };
    
    fetch(url, options)
      .then( res => res.json() )
      .then( data => console.log(data) );
    

提交回复
热议问题