在驱动器请求集HTTP头 [英] Set HTTP header in Drive request
本文介绍了在驱动器请求集HTTP头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要更新文件,驱动器时检测到冲突。要做到这一点,看来我必须设置如果-匹配
头一>
I want to detect conflict when updating a file to Drive. To accomplish this, it seems I have to set the If-Match
header.
目前,我与这一个班轮更新文档到谷歌驱动器:
Currently, I update the doc to Google Drive with this one-liner:
mDriveFile = mService.files().update(mDriveFile.getId(), mDriveFile, byteContent).execute();
什么是添加如果-匹配
头在请求中最简单的方法? 实例文件:更新文档没有告诉如何设置HTTP标头。
What is the simplest way to add the If-Match
header in the request? Example in Files: update documentation does not tell how to set HTTP headers.
推荐答案
您可以从更新获得标题
对象,添加自己,并把他们带回执行HTTP前要求:
You can get the headers from Update
object, add your own and put them back before executing the HTTP request:
final Update update = mService.files().update(mDriveFile.getId(), mDriveFile, byteContent);
final HttpHeaders headers = update.getRequestHeaders();
headers.setIfMatch("TheETagStoredFromDownload");
update.setRequestHeaders(headers);
mDriveFile = update.execute();
这篇关于在驱动器请求集HTTP头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文