Giter Site home page Giter Site logo

cordova-plugin-fetch's People

Contributors

alexdisler avatar aporat avatar ebhsgit avatar helllamer avatar hellonuh avatar kbalasub avatar leandromsales avatar mirodil avatar sokcuri avatar tiecia avatar vially avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

cordova-plugin-fetch's Issues

Android: "Content-Type": "application/json" does not 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!

If response body does not have ContentType plugin crash

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")) {

WKWebView compatibility

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.

Update npm / add response.ok & response.json

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!

Fetch trapped in pending forever if app goes into the background

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?

Getting chunked data

Hi,

Is it possible to get large files in chunked arraybuffers with cordova-plugin-fetch?

Can't compile

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'
}

response.json is not a function

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 ?

Support for multiple cookies

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?

Can't install, weird dependency to phonegap-plugin-push

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 ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.