无法为 http 目标设置自定义 header 字段
unable to set custom header field for a http destination
我想为指定目的地设置额外的 header 字段。默认调用有效。
示例:
Destination destination = DestinationAccessor.getDestination("xyz");
Data data = new DefaultXyzService()
.withServicePath("/sap/opu/odata/sap/Z_XYZ_SRV")
.getDataByKey(id)
.execute(destination);
但是如何设置自定义 header 字段?
类似的东西
List<Header> headers = new ArrayList<Header>();
final Header HEADER = new Header("X-XYZ-ENDUSERNAME", id);
headers.add(HEADER);
DefaultHttpDestination destination2 = new DefaultHttpDestination(destination.asHttp(), headers);
Data data = new DefaultXyzService()
.withServicePath("/sap/opu/odata/sap/Z_XYZ_SRV")
.getDataByKey(id)
.execute(destination2);
导致错误消息:"Unable to fetch the metadata : Error fetching the metadata"
使用版本 3.1.0。
谢谢并致以最诚挚的问候,
沃尔克
API 建议 SAP Cloud SDK 的消费者使用“withHeader”方法来定义单个 HTTP 请求headers 他们的 OData 查询:
new DefaultXyzService()
.withServicePath("/sap/opu/odata/sap/Z_XYZ_SRV")
.getDataByKey(id)
// only on entity request
.withHeader("foo", "bar").onRequestOnly()
// on all requests, including $metadata lookup
.withHeader("fizz", "buzz").onRequestAndImplicitRequests()
.execute(destiantion.asHttp());
我想为指定目的地设置额外的 header 字段。默认调用有效。
示例:
Destination destination = DestinationAccessor.getDestination("xyz");
Data data = new DefaultXyzService()
.withServicePath("/sap/opu/odata/sap/Z_XYZ_SRV")
.getDataByKey(id)
.execute(destination);
但是如何设置自定义 header 字段? 类似的东西
List<Header> headers = new ArrayList<Header>();
final Header HEADER = new Header("X-XYZ-ENDUSERNAME", id);
headers.add(HEADER);
DefaultHttpDestination destination2 = new DefaultHttpDestination(destination.asHttp(), headers);
Data data = new DefaultXyzService()
.withServicePath("/sap/opu/odata/sap/Z_XYZ_SRV")
.getDataByKey(id)
.execute(destination2);
导致错误消息:"Unable to fetch the metadata : Error fetching the metadata"
使用版本 3.1.0。
谢谢并致以最诚挚的问候,
沃尔克
API 建议 SAP Cloud SDK 的消费者使用“withHeader”方法来定义单个 HTTP 请求headers 他们的 OData 查询:
new DefaultXyzService()
.withServicePath("/sap/opu/odata/sap/Z_XYZ_SRV")
.getDataByKey(id)
// only on entity request
.withHeader("foo", "bar").onRequestOnly()
// on all requests, including $metadata lookup
.withHeader("fizz", "buzz").onRequestAndImplicitRequests()
.execute(destiantion.asHttp());