Set HTTP header in Drive request

蹲街弑〆低调 提交于 2019-12-11 12:27:48

问题


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();

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.


回答1:


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();


来源:https://stackoverflow.com/questions/21968822/set-http-header-in-drive-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!