【问题标题】:Cannot access HTTP headers from Cloud Endpoints Python无法从 Cloud Endpoints Python 访问 HTTP 标头
【发布时间】:2014-08-23 19:14:39
【问题描述】:

我正在 Google Cloud Endpoints 中为 Android 应用实施自定义身份验证。为此,我在 HTTP 标头中发送了一个身份验证令牌。来自安卓:

private static final String HEADER_AUTH_TOKEN = "HTTP_AUTHORIZATION";

private GoogleClientRequestInitializer requestInitializer =
    new GoogleClientRequestInitializer() {

   @Override
   public void initialize(AbstractGoogleClientRequest<?> request) throws IOException {
      HttpHeaders headers = request.getRequestHeaders();
      if (authPrefs.authToken().exists()) {
          headers.set(HEADER_AUTH_TOKEN, authPrefs.authToken().get().toString());
      }
      request.setRequestHeaders(headers);
   }
};

Api.Builder apiBuilder = new Api.Builder(
    AndroidHttp.newCompatibleTransport(),
    new GsonFactory(),
    null);

return apiBuilder.setApplicationName(APPLICATION_NAME)
         .setGoogleClientRequestInitializer(requestInitializer)
         .build()

然后在 Python 中,我尝试检索身份验证令牌标头:

import os
auth_token = os.getenv('HTTP_AUTHORIZATION')

auth_token 为无。我错过了什么?

【问题讨论】:

    标签: android python google-app-engine google-cloud-endpoints


    【解决方案1】:

    事实证明,“HTTP_”被附加到任何发送的 HTTP 标头中。 HTTP_AUTHORIZATION 正在作为“HTTP_HTTP_AUTHORIZATION”发送。

    【讨论】:

      猜你喜欢
      • 2017-07-20
      • 2013-02-09
      • 1970-01-01
      • 1970-01-01
      • 2021-07-25
      • 2015-07-16
      • 1970-01-01
      • 2016-02-13
      • 2023-03-14
      相关资源
      最近更新 更多