I have an API working with Cloud Endpoints and I added its generated client library to my Android app.
我有一个使用Cloud Endpoints的API,我将其生成的客户端库添加到我的Android应用程序中。
However I don't know how to add information to my requests. For now, here is the only HTTP request I know how to send using the client library:
但是我不知道如何在我的请求中添加信息。现在,这是我知道如何使用客户端库发送的唯一HTTP请求:
DrinkEndpoint.Builder builder = new DrinkEndpoint.Builder(AndroidHttp.newCompatibleTransport(),new GsonFactory(), null);
DrinkEndpoint service = builder.build();
Drink drink = new Drink();
drink.setName(params[0]);
response = service.insertDrink(drink).execute();
So my question is: how to modify this request to add information either in the headers or in the body of the request? For instance, I want to add a String that is not an attribute of the Drink entity.
所以我的问题是:如何修改此请求以在标头或请求正文中添加信息?例如,我想添加一个不是Drink实体属性的String。
Thank you
谢谢
1 个解决方案
#1
1
Your insertDrink(drink)
method returns a InsertDrink
instance which is a child of InsertDrinkEndpointRequest
.
The InsertDrinkEndpointRequest
instance allows you to set the request header by calling the setRequestHeaders(httpHeader)
method.
In your case: service.insertDrink(drink).setRequestHeaders(httpHeader).execute()
.
您的insertDrink(drink)方法返回InsertDrink实例,该实例是InsertDrinkEndpointRequest的子项。 InsertDrinkEndpointRequest实例允许您通过调用setRequestHeaders(httpHeader)方法来设置请求标头。在你的情况下:service.insertDrink(drink).setRequestHeaders(httpHeader).execute()。
This way of building a cloud endpoint request may help you: https://*.com/a/21492950/2205582
这种构建云端点请求的方式可以帮助您:https://*.com/a/21492950/2205582
#1
1
Your insertDrink(drink)
method returns a InsertDrink
instance which is a child of InsertDrinkEndpointRequest
.
The InsertDrinkEndpointRequest
instance allows you to set the request header by calling the setRequestHeaders(httpHeader)
method.
In your case: service.insertDrink(drink).setRequestHeaders(httpHeader).execute()
.
您的insertDrink(drink)方法返回InsertDrink实例,该实例是InsertDrinkEndpointRequest的子项。 InsertDrinkEndpointRequest实例允许您通过调用setRequestHeaders(httpHeader)方法来设置请求标头。在你的情况下:service.insertDrink(drink).setRequestHeaders(httpHeader).execute()。
This way of building a cloud endpoint request may help you: https://*.com/a/21492950/2205582
这种构建云端点请求的方式可以帮助您:https://*.com/a/21492950/2205582