修改在谷歌应用程序引擎端点的HTTP标头(安卓) [英] Modify HTTP headers in Google App Engine Endpoints (Android)

查看:167
本文介绍了修改在谷歌应用程序引擎端点的HTTP标头(安卓)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想自定义标题添加到发送到端点的HTTP包。我读过,我可以访问端点方法原始的HTTP数据(通过添加一个HttpServletRequest的参数)。我所寻找的是一个解决方案(或黑客攻击)来访问和修改发送的(安卓)客户端的数据。

I would like to add custom headers to the HTTP package sent to an Endpoint. I've read that I can access the raw HTTP data in the Endpoint method (by adding a HttpServletRequest parameter). What I am looking for is a solution (or a hack) to access and modify the data being sent by the (Android) client.

推荐答案

HTTP标头可以修改这个样子。我用这个链接为例。因为它是谷歌的例子之一。

Http headers can be modified like this. I use this link as example. Since it's one of the Google's example.

阅读它,找到 EndpointsAsyncTask 您可以使用 GoogleClientRequestInitializer 这一点。在

Read it and find EndpointsAsyncTask you can use GoogleClientRequestInitializer for this. inside

公共无效初始化(AbstractGoogleClientRequest abstractGoogleClientRequest)抛出IOException异常

public void initialize(AbstractGoogleClientRequest abstractGoogleClientRequest) throws IOException

您可以设置标题是这样的。

you can set headers like this.

HttpHeaders headers = abstractGoogleClientRequest.getRequestHeaders();
headers.setDate(dateFormat.format(calendar.getTime()));
headers.set("MyCustomHeader", "HeaderValue");
abstractGoogleClientRequest.setRequestHeaders(headers);

在上面的code的setDate()可用于设置日期的头部,设()方法被用来设置我自己的头,可以从服务器端读取。我已经使用日历类来获得日期,但日历类的初始化这里没有显示。

In above code setDate() can be used to set Date header and set() method has been used to set my own header that can be read from server side. I have used calendar class to get date but Calendar class initialization is not shown here.

我还写上我的博客一张纸条,以显示它是如何实际居住在该方法中。如果你喜欢阅读的了。

I have also write a note on my blog to show how it's actually reside in the method. if you like read that too.

这篇关于修改在谷歌应用程序引擎端点的HTTP标头(安卓)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆