简体   繁体   English

从 Cordova 发送原生 HTTP 请求

[英]Send native HTTP request from Cordova

I am not that familiar with native Android development, I have some experience in Web development我对原生Android开发不是很熟悉,我有一些Web开发经验

I am trying create a hybrid android app using Cordova, I know how to send an AJAX request but you can not send that http requests to all website, becuase orgin policy, but the native Java can send that kind of HTTP request我正在尝试使用 Cordova 创建一个混合 android 应用程序,我知道如何发送 AJAX 请求,但您不能将 http 请求发送到所有网站,因为来源策略,但本机 Java 可以发送那种 HTTP 请求

I saw lot of people creating plugins that makes native API available to JavaScript, so is there any plugin in cordova that can send http request without the problem of origin policy?我看到很多人在创建插件,使原生 API 可用于 JavaScript,那么cordova 中是否有任何插件可以发送 http 请求而不会出现源策略问题?

Yes exists, and works very well, we are using on our project the plugin cordova-plugin-advanced-http , based on cordova-HTTP .是的,并且运行良好,我们在我们的项目中使用了基于cordova-HTTP的插件cordova-plugin-advanced-http

The project is a onsen/angularjs/cordova, and the plugin work without CORS errors, normal :), now we are evaluating if is more efficient native HTTP calls or javascript HTTP calls, the author of the plugin cite three good motivations to change for native calls:该项目是一个onsen/angularjs/cordova,插件工作没有CORS错误,正常:),现在我们正在评估是否更有效的原生HTTP调用或javascript HTTP调用,插件的作者列举了三个很好的改变动机本地调用:

Background threading - all requests are done in a background thread.
Handling of HTTP code 401 - read more at Issue CB-2415.
https://issues.apache.org/jira/browse/CB-2415
SSL Pinning - read more at LumberBlog.
http://blog.lumberlabs.com/2012/04/why-app-developers-should-care-about.html

The plugin offer a good documentation, and is easy to use with simple POST , PUT , DELETE and GET methods.该插件提供了一个很好的文档,并且易于使用简单的POSTPUTDELETEGET方法。 Is possible set Headers and another presets.可以设置标题和其他预设。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM