c# - 如何在YouTube API v3的.Net客户端库中指定ETag

标签 c# .net youtube youtube-api etag

YouTube API v3文档建议使用ETag以获得更好的性能:

Your application can cache API resources and their ETags. Then, when your application requests a stored resource again, it specifies the ETag associated with that resource. If the resource has changed, the API returns the modified resource and the ETag associated with that version of the resource. If the resource has not changed, the API returns an HTTP 304 response (Not Modified)



Getting Started with the YouTube Data API\Optimizing performance\Using ETags

我的问题是如何使用.Net客户端库指定关联的ETag?

最佳答案

使用etags的一般想法是,请求在请求中添加一个“If-None-Match” header ,该 header 设置为etag的值。服务器已经配置为通过检查etag并响应304来响应该 header ,如果没有任何更改。因此,实际上,这取决于给定的客户端库是否支持添加自定义 header (例如“If-None-Match”),然后具有代码来处理304(如果返回的话)(或者是否替换其缓存)。 。

我知道YouTube javascript库确实可以做到(在构造gapi.client.request对象时,您只是传递了具有附加 header 的“ header ”对象),但是从我对.Net客户端代码(https://code.google.com/p/google-api-dotnet-client/source/browse/Src/GoogleApis.Core/Apis/Requests/RequestBuilder.cs)的粗浅阅读中,看来.Net客户端不允许您当前设置此 header 。您始终可以在客户端结构之外发出直接GET请求,或者扩展客户端以包括功能,只要您随后还处理了缓存部分。但是,我可能是错误的,并且输入了错误的代码。

关于c# - 如何在YouTube API v3的.Net客户端库中指定ETag,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26163321/

相关文章:

c# - Regular Expressions-VAlidation String-REAL菜鸟问题:)

c# - 使用 Microsoft Asp.NET 依赖注入(inject)时找不到 HttpActionContext.get_Request() 方法

c# - 在运行时(构建时)创建 T4 模板?

.net - 代码执行期间缓存(或其他变量)是否可以更改?

c# - Paypal 支付和 .NET 确认/检查页面

youtube - Google Play促销视频未在移动设备中显示,但通过笔记本电脑浏览器可见

c# - 更改 Xamarin.Forms 中背景图像的纵横比,同时保持内容居中

c# - Jquery 模态未调整大小

.net - 从youtube链接获取youtube嵌入视频代码?

javascript - 带有youtube视频的视频库-无法嵌入