aporat / cordova-plugin-fetch Goto Github PK
View Code? Open in Web Editor NEWHTTP networking plugin that brings the fetch() standard to Cordova
HTTP networking plugin that brings the fetch() standard to Cordova
Hi @aporat and @AlexDisler,
In a simple test I was running, the webserver sent the following response header:
Date: Thu, 26 Nov 2015 23:07:42 GMT
Server: Apache/2.4.16 (Unix)
Set-Cookie: CookieTesteName1=CookieTesteValue1; expires=Fri, 27-Nov-2015 00:07:42 GMT; Max-Age=3600; path=/folder; domain=.domain.com; secure
Set-Cookie: CookieTesteName2=CookieTesteValue2; expires=Fri, 27-Nov-2015 00:07:42 GMT; Max-Age=3600; path=/folder; domain=.domain.com; secure
CustomHeaderName: CustomHeaderValue
Content-Length: 2397
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html
Please, note that there is two "Set-Cookie", but response.headers["Set-Cookie"] using cordova-plugin-fetch only returns a string containing the last "Set-Cookie" value. Is this the expected result?
Hi,
I added cordova-plugin-fetch
to a meteor project, but it wont install. It fails with this error message:
While adding plugin [email protected] to Cordova project:
Uh oh!
"/home/eric-burel/Websites/simply-charge/.meteor/local/cordova-build/plugins/cordova-plugin-fetch/src/android/com/adobe/phonegap/push/PushPlugin.java" not found!
at copyFile (/home/eric-burel/Websites/simply-charge/.meteor/local/cordova-build/platforms/android/cordova/lib/pluginHandlers.js:219:36)
at copyNewFile (/home/eric-burel/Websites/simply-charge/.meteor/local/cordova-build/platforms/android/cordova/lib/pluginHandlers.js:250:5)
at install (/home/eric-burel/Websites/simply-charge/.meteor/local/cordova-build/platforms/android/cordova/lib/pluginHandlers.js:43:17)
at ActionStack.process (/home/eric-burel/Websites/simply-charge/.meteor/local/cordova-build/platforms/android/cordova/node_modules/cordova-common/src/ActionStack.js:56:25)
at PluginManager.doOperation (/home/eric-burel/Websites/simply-charge/.meteor/local/cordova-build/platforms/android/cordova/node_modules/cordova-common/src/PluginManager.js:117:20)
at PluginManager.addPlugin (/home/eric-burel/Websites/simply-charge/.meteor/local/cordova-build/platforms/android/cordova/node_modules/cordova-common/src/PluginManager.js:147:17)
at /home/eric-burel/Websites/simply-charge/.meteor/local/cordova-build/platforms/android/cordova/Api.js:254:18
at _fulfilled (/home/eric-burel/Websites/simply-charge/.meteor/local/cordova-build/platforms/android/cordova/node_modules/q/q.js:854:54)
at self.promiseDispatch.done (/home/eric-burel/Websites/simply-charge/.meteor/local/cordova-build/platforms/android/cordova/node_modules/q/q.js:883:30)
at Promise.promise.promiseDispatch (/home/eric-burel/Websites/simply-charge/.meteor/local/cordova-build/platforms/android/cordova/node_modules/q/q.js:816:13)
at /home/eric-burel/Websites/simply-charge/.meteor/local/cordova-build/platforms/android/cordova/node_modules/q/q.js:570:49
at runSingle (/home/eric-burel/Websites/simply-charge/.meteor/local/cordova-build/platforms/android/cordova/node_modules/q/q.js:137:13)
at flush (/home/eric-burel/Websites/simply-charge/.meteor/local/cordova-build/platforms/android/cordova/node_modules/q/q.js:125:13)
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)
I don't understand because there is no dependency to this plugin, maybe it is loaded by some other lib ?
At FetchPlugin.java line 123, when trying to check if response is a image if the response does not have ContentType it throw null pointer exception.
This changes address this issue for me
at line 123 i change from
if (response.body().contentType().type().equals("image")) {
to
if (response.body().contentType() != null && response.body().contentType().type().equals("image")) {
Hi @aporat !
Great project. It's a life saver.
This plugin enables using iOs' wkwebview and still be able to access cookies. That is a must in many projects. It also allows not having to deal with CORS configuration on the server.
wkwebview hides cookies to the user even with the combination of CORS + running Cordova from a local webserver. The cross-domain cookie issue is still there. StackOverflow is full of questions about wkwebview + CORS + cookies.
Cordova-plugin-fetch is a nice work around. Your plugin would be super popular if more people knew about it.
In addition to your plugin, I implemented a small wrapper around "cordovaFetch" that transparently takes care of cookie parsing, storing and retrieval using localStorage. This permits using wkwebview + cookies as usually done in the browser as long as cookies are not only set/retrieved from the server (and not using document.cookie
).
I also implemented another small wrapper that adds a "response.ok" and "response.json". I found these properties were not being set (only checked on iOS). This can also be done with a wrapper around cordovaFetch.
That said, it would be amazing if you could update to npm with the last changes that have been pulled 6 months ago.
I'm also not sure how difficult would it be to fix add .ok & .json to the response object. Also, if you feel adventurous it would be great to handle cookies transparently within cordovaFetch as I mentioned above. Or maybe, you might be interested in a small piece of code that would implement that in Javascript. I would be willing to contribute if that is the case.
It would be great hearing about people with skills on native development willing to contribute to the project.
Thanks again and keep up the good work!
Hello,
The plugin works flawlessly on iOS.
On Android though, I get an error that the Content-Type is not set as "application/json".
I have explicitly set the headers as:
headers: { "Accept": "application/json", "Content-Type": "application/json" }
Any idea why this is not working on Android? Have a near production app, so very critical I figure this out.
Thanks!
So when attempt to send a PATCH request with a postBody causes the fetch API to instead send a POST instead of a PATCH.
Will dig into the code but not sure why I am getting this behavior
Hi there,
(question at the very end)
due to Apple's deprecation of UIWebView we need to switch to WKWebView
. We could solve cookie issues using cordova-plugin-wkwebview-file-xhr
for making AJAX requests. But we are not able to load HTML assets (image for instance via <img src="..." >
) which are accessible with a valid session cookie only.
So now i was thinking to make API calls using cordova-plugin-fetch
instead of using cordova-plugin-wkwebview-file-xhr
and being able to receive cookies via
cordovaFetch('/users.json')
.then(function(response) {
console.log(res.headers['Set-Cookie']);
})
and inject this cookie into the WKWebView
by using cordova-plugin-wkwebview-inject-cookie like
cookiesArray = [{
domain: 'abc.xyz',
name: 'cookie name',
path: '/',
value: 'cookie string'
},{...}]
wkWebView.injectCookie(cookiesArray);
It would require quite a bit of refactoring to be able to test this scenario. That's why i want to ask beforehand if this plugin works with WKWebView
flawlessly.
Thx.
Hi,
I get the following error on IOS using this plugin:
TypeError: response.json is not a function. (In 'response.json()', 'response.json' is undefined)
const url = API_URL + '/version';
fetch(url)
.then((response) => { response.json(); } )
.then((jsonResponse) => {
_onGetRemoteVersionSuccess(jsonResponse);
})
.catch((error) => {
_onGetRemoteVersionError(error);
});
Can you help me with this please ?
Following the example, no data is posted. In the console I see
V FetchPlugin: execute: postBody = {}
When I manually encode the form data, add appropriate headers, and pass a string as body
, everything works as expected.
Using
Hello,
This is an awesome plugin for cordova.
I'm trying to make it work in Meteor-cordova and it looks like there are compatibility issues.
meteor/meteor#6356
Just wanted to understand if theres a way to fix this. Thanks!
More info:
In Xcode, build fails with this error:
FetchPlugin.h
Cordova/CDVJSON.h file not found
I'm at v11 of Cordova and Android platform and this plugin can't compile. It complains about compile
in dependencies.gradle.
I fixed the issue by changing the word to implementation
, but I'm not sure whether it's correct. Anyway, the full file is now:
apply plugin: 'maven-publish'
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
implementation 'com.squareup.okhttp3:okhttp:4.9.0'
}
This is a common issue I have experienced trying to get any sort of HTTP request to work while the app is in the background.
I am using a plugin call https://github.com/transistorsoft/cordova-plugin-background-fetch to execute a little code every once in a while that goes out and fetches some data via our API.
The problem is when the app is placed into the background these fetches are stuck in "pending" until the app get foreground again. I can see this through the chrome debugger.
I have only had one plugin that actually can perform HTTP API requests successfully while the app is running in the background however it had it's own issues.
Any idea how it could be made possible to get requests to work while the app is in the background?
Hi,
Is it possible to get large files in chunked arraybuffers with cordova-plugin-fetch
?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.