fetch-api

Submitting multiple files to ASP.NET controller accepting an ICollection<IFormFile>

落爺英雄遲暮 提交于 2019-11-30 15:32:32
问题 In my ASP.NET Core backend, I have a controller function that looks like this: [HttpPost] [Route("documents/upload")] public async Task<IActionResult> UploadFile(ICollection<IFormFile> files) { ... } In my front-end, I call the function like this: var postSettings = { method: 'POST', credentials: 'include', mode: 'cors' } uploadDocuments( files ) { var data = new FormData(); data.append('files', files); postSettings.body = data; return fetch(endPoint + '/documents/upload', postSettings); } If

Using fetch API with mode: 'no-cors', can’t set request headers

帅比萌擦擦* 提交于 2019-11-30 14:15:15
I am trying to hit a service end point and the service is a login service I am using the authentication type as basic ,The code is in react and using the fetch library however even if i set the headers field in my request I am unable to see the values of corresponding headers in my request in network tab? Following is the code : var obj = { method: 'GET' , mode : 'no-cors', headers: { 'Access-Control-Request-Headers': 'Authorization', 'Authorization': 'Basic amFzcGVyYWRtaW46amFzcGVyYWRtaW4=', 'Content-Type': 'application/json', 'Origin': '' }, credentials: 'include' }; fetch('http://myreport

Enable CORS in fetch api [duplicate]

跟風遠走 提交于 2019-11-30 13:53:20
问题 This question already has answers here : How does Access-Control-Allow-Origin header work? (14 answers) Closed last year . I am getting the following error message that unable me to continue Failed to load https://site/data.json: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. If an opaque response serves your needs, set the request's

What is the difference between isomorphic-fetch and fetch?

我的未来我决定 提交于 2019-11-30 13:35:45
问题 I've seen two different fetch here: https://github.com/github/fetch https://github.com/matthew-andrews/isomorphic-fetch Can someone tell me the difference between the two? PS: I've read the README.md but I still didn't get the difference. Last time I checked, Isomorphic means it has similar form or relation. It still doesn't make sense to me. 回答1: FETCH is polyfill for browsers which don't have fetch function (caniuse.com/#search=fetch). It will add fetch function to your browser window

Enable CORS in fetch api [duplicate]

我与影子孤独终老i 提交于 2019-11-30 12:38:16
This question already has an answer here: How does Access-Control-Allow-Origin header work? 13 answers I am getting the following error message that unable me to continue Failed to load https://site/data.json : Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' http://localhost:8080 ' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled. localhost/:1 Uncaught (in promise) TypeError: Failed to fetch

What is the difference between fetch and jquery ajax?

落爺英雄遲暮 提交于 2019-11-30 11:15:09
I want to send a post request through fetch, but it does not work. But if I do it through jQuery ajax, it succeeds. I want to know the difference of the two way and if there is anything wrong in my use of fetch here: fetch('http://localhost:8888/news',{ method:"post", data:"code=7&a=8&b=9" }).then(function(data){ data.json().then(function (json) { } Fetch specification differs from jQuery.ajax() in mainly two ways: The Promise returned from fetch() won’t reject on HTTP error status even if the response is an HTTP 404 or 500. Instead, it will resolve normally (with ok status set to false), and

Fetch Api:Can not get data from localhost

帅比萌擦擦* 提交于 2019-11-30 09:26:09
问题 I have been trying to create an android app using nativescript.I am using fetch module to get response from my server.When I am trying to get response from httpbin.org/get ,it is OK.But when I am trying to get response from my local server,I am getting Network Request Failed. error. Sending to httpbin.org/get- return fetchModule.fetch("https://httpbin.org/get").then(response => { return response.text(); }).then(function (r) { console.log(r); }, function (e) { console.log(e); }); Sending to

Cleanest way to handle custom errors with fetch & ES6 promise

我是研究僧i 提交于 2019-11-30 09:24:42
I am trying to intelligently handle the success/error responses from our API using fetch & ES6 promises. Here is how I need to handle response statuses: 204: has no json response, but need to treat as success 406: should redirect to sign in 422: has json for error message < 400 (but not 204): success, will have json >= 400 (but not 422): error, will not have json So, I am struggling with how to write this cleanly. I have some less than stellar code working right now that looks like this: fetch() .then(response => checkStatus(response)) .then(parseJSON) //will throw for the 204 .then(data =>

How to extend the 'Window' typescript interface

只愿长相守 提交于 2019-11-30 08:11:13
In my example, I'm trying to extend the TS Window interface to include a polyfill for fetch . Why doesn't matter. The question is " how do I tell TS that window.fetch is a valid function? " I'm doing this in VS Code, v.0.3.0 which is running TS v.1.5 (IIRC). Declaring the interface inside my TS class file where I want to use it doesn't work: ///<reference path="typings/tsd.d.ts"/> interface Window { fetch:(url: string, options?: {}) => Promise<any> } ... window.fetch('/blah').then(...); // TS objects that window doesn't have fetch But it's OK if I declare this same interface in a separate ".d

What is the difference between isomorphic-fetch and fetch?

对着背影说爱祢 提交于 2019-11-30 07:49:22
I've seen two different fetch here: https://github.com/github/fetch https://github.com/matthew-andrews/isomorphic-fetch Can someone tell me the difference between the two? PS: I've read the README.md but I still didn't get the difference. Last time I checked, Isomorphic means it has similar form or relation. It still doesn't make sense to me. Sergey FETCH is polyfill for browsers which don't have fetch function ( caniuse.com/#search=fetch ). It will add fetch function to your browser window object. While isomorphic-fetch is implementation of fetch for both node.js and browser, built on top of