fetch

Fetch post request works but axios post does not?

谁都会走 提交于 2021-01-29 20:39:57
问题 Currently trying to convert a working fetch POST request into an Axios POST request, however, I keep getting the error "Error: Request failed with status code 400". The function is a post request to the Spotify API to obtain an authentication token. Would greatly appreciate any help :) This is the current Fetch POST request that works : const result = await fetch('https://accounts.spotify.com/api/token', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded',

Decoding Exchange Rate JSON in SwiftUI

笑着哭i 提交于 2021-01-29 20:10:44
问题 I am trying to decode https://api.exchangeratesapi.io/latest, provided by Exchange Rates API. I'm applying several tutorials I found online, but when I apply my own details, I get an error. My code looks as following: struct Response: Codable { var results: [Result] } struct Result: Codable { let base: String let date: String let rates: [String:Double] } The function to retrieve the data: func loadData() { guard let url = URL(string: "https://api.exchangeratesapi.io/latest") else { print(

fetch ImageData - Missing boundary in multipart/form-data - Patch

跟風遠走 提交于 2021-01-29 11:22:13
问题 There are thousands of questions similar to this one but somehow I failed to find my answer. Some of them like this suggest setting the Content-Type to undefined . Others suggest removing the Content-Type like this. I tried both. If I set the Content-Type to multipart/form-data , I face with Failed to read the request form. Missing content-type boundary. . I even tried to add custom boundaries like multipart/form-data; boundary=--XXX-- and faced with Failed to read the request form. Multipart

How to upload a csv file to blob storage using axios/fetch (nodejs)

送分小仙女□ 提交于 2021-01-29 10:41:09
问题 I am trying to automate (for test automation) the upload/download/validate the csv file data for an application hosted in Azure cloud and was following the article: https://medium.com/@fakiolinho/handle-blobs-requests-with-axios-the-right-way-bb905bdb1c04 And tried to implement it as directed, however, couldn't find the ' actionTypes ' in the following (action.js): import * as types from './actionTypes'; and got a bit lost to start over. [Error: Cannot find module './actionTypes'] Based on my

Fetch in Internet Explorer?

放肆的年华 提交于 2021-01-29 09:22:53
问题 Following code does not work on IE at all. fetch("{{{LINK TO API}}}", { headers: { "Accept": "application/json", "Content-Type": "application/json" } }) .then(resp => resp.json()) .then(function(json) { // SET VARIABLES var seller = json.sellers[Math.floor(Math.random() * Math.floor(json.sellers.length))]; // INSERT COMPANY LOGO companyLogo.src = json.logo_url; // INSERT SELLER PROFILES document.querySelectorAll("[data-seller-profile]").forEach(wrapper => { var innerHTML = ""; innerHTML += "

React Native Deck Swiper

对着背影说爱祢 提交于 2021-01-29 09:17:23
问题 I am trying to make a GET request to an enpoint using the two functional components below to display in my react native deck swipper //using fetch const getDataUsingFetch = () => { fetch(latestNews+ApiKey) .then((response) => response.json()) .then((responseJson) => { // set the state of the output here console.log(responseJson); setLatestNews(responseJson); }) .catch((error) => { console.error(error); }); } //using anxios //asynchronous get request call to fetech latest news const

How do I set up a GCP App Engine instance with CORS?

一笑奈何 提交于 2021-01-29 08:31:29
问题 I've set up two different GCP App Engine apps. One is an express server (let's call it foo) with the following app.yaml: runtime: nodejs10 handlers: - url: /tasks static_dir: /tasks http_headers: Access-Control-Allow-Origin: https://bar.appspot.com/ secure: always From my bar app, I'm trying to do a fetch call: const response = await fetch('https://foo.appspot.com/tasks'); Every time I try this, however, Chrome blocks my request with the 'has been blocked by CORS policy: No 'Access-Control

Fetch : Argument of type 'string | undefined' is not assignable to parameter of type 'RequestInfo'

北城以北 提交于 2021-01-29 08:27:09
问题 Im receiving the following error in the "fetchUrl" argument in the fetch function Argument of type 'string | undefined' is not assignable to parameter of type 'RequestInfo'. In this function let fetchUrl = getBaseUrlNative( process.env.APP_DATA, `/v2/marketing/app/file/${file}?cookies=${cookieSess}&expires=${Date.now()}`) await fetch(fetchUrl, { method: 'get' , cache:"no-store" , headers: { 'Cache-Control': 'no-cache' }}) .then(res => res.blob()) .then(res => { ....... getBaseUrlNative is

Using JavaScript Fetch Returns Pending Promise

前提是你 提交于 2021-01-29 07:52:49
问题 I'm fetching text from a Dictionary API and I can't quite figure out why my code returns a pending promise. However logging the value returns the intended text. Here is my code, const getWord = (difficulty) => { const fetchParameters = api + "?difficulty=" + difficulty let outputWord = fetchWord(fetchParameters).then(value => { console.log(value) // ->Logs intended text return value }) return outputWord // -> Returns Pending Promise } async function fetchWord(fetchParams) { const response =

How to wait a Promise inside a forEach loop

我只是一个虾纸丫 提交于 2021-01-29 00:58:36
问题 I'm using some Promise() functions to fetch some data and I got stuck with this problem on a project. example1 = () => new Promise(function(resolve, reject) { setTimeout(function() { resolve('foo1'); }, 3000); }); example2 = () => new Promise(function(resolve, reject) { setTimeout(function() { resolve('foo2'); }, 3000); }); doStuff = () => { const listExample = ['a','b','c']; let s = ""; listExample.forEach((item,index) => { console.log(item); example1().then(() => { console.log("Fisrt"); s =