简体   繁体   English

访问angularJS中的HTTP标头

[英]Accessing http headers in angularJS

We are having two applications. 我们有两个应用程序。 One is written running on salesforce (App A and other app (App B) is using angularJS for UI. 一个是在salesforce上运行的(应用程序A,另一个是应用程序(应用程序B))是使用angularJS编写的。

When a user performs a certain actions in App A, App B has to be opened in a new tab. 当用户在App A中执行某些操作时,必须在新选项卡中打开AppB。 In this case, certain parameters have to be passed to App B from App A. 在这种情况下,某些参数必须从App A传递到AppB。

As App A and App B are running in different domain we can't use cookies to share the data. 由于App A和App B在不同的域中运行,因此我们无法使用Cookie共享数据。

So we wanted to pass it as a http header. 因此,我们希望将其作为http标头传递。 Is it possible to read the http header in angular JS? 是否可以在angular JS中读取http标头?

Please note that this different from AngularJS - accessing http headers . 请注意,这与AngularJS不同-访问http标头 That was related when we access a http from angular JS. 当我们从角度JS访问http时,这是相关的。 But we want to read the http headers passed to our angularJS application. 但是我们想读取传递给我们的angularJS应用程序的http标头。

How can we read the HTTP headers sent to an angular JS application? 我们如何读取发送到有角JS应用程序的HTTP标头? Or is there any better approach to solve this issue? 还是有更好的方法来解决这个问题?

You can access headers from $http or from $resource but depends on what you are trying to do. 您可以从$ http或$ resource访问标头,但取决于您要执行的操作。 If passing the state/data then it might not be possible. 如果传递状态/数据,则可能无法实现。

pass as query string in the App B URL and open in new window/tab. Login information might not persist in second domain if you are not using Auth2/Auth domain authorization method and not sending data using get method with request data when opening in new tab or window. 如果您未使用Auth2 / Auth域授权方法,并且在新选项卡或窗口中打开时未sending data using get method with request data则登录信息可能不会保留在第二个域中。

You need the assistance from server side, you don't have the access to page headers in JS, and it isn't Angular issue. 您需要服务器端的帮助,您无权访问JS中的页面标题,这也不是Angular的问题。

You can try cross-domain localStorage with this package . 您可以使用此包尝试跨域localStorage It also has Angular module bundled. 它还捆绑了Angular模块。

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

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