Google sites API, IllegalArgumentException(“Trying to set foreign cookie”) after RedirectRequiredException

北城以北 提交于 2019-12-07 09:09:02

问题


I am using the gdata-media-1.0-1.47.1.jar functionality to fetch media data using the com.google.gdata.client.media.MediaService.getMedia(IMediaContent mediaContent) method. For some requests I get a RedirectRequiredException. When I redo the getMedia request, using the url i get from RedirectRequiredException.getRedirectLocation(), I get an IllegalArgumentException("Trying to set foreign cookie") exception.

From what I can see, the reason for this is that the domain in the response header for the cookie doesn't match the domain of the redirect location. In com.google.gdata.client.http.GoogleGDataRequest.matchDomain() the first argument is ".docs.google.com" and the second is "docs.google.com" which makes the domain matching fail.

Is this a correct behaviour? Why is this happening? Is there something I can do about this? Am I doing anything wrong here? Is is possible to avoid this problem?

SitesService sitesService = new SitesService("SomeAppName");
try {
    MediaContent mc = new MediaContent();
    mc.setUri(aURI);
    return sitesService.getMedia(mc);
} catch (RedirectRequiredException e) {
    MediaContent mc = new MediaContent();
    mc.setUri(e.getRedirectLocation());
    return sitesService.getMedia(mc);
}

来源:https://stackoverflow.com/questions/20702752/google-sites-api-illegalargumentexceptiontrying-to-set-foreign-cookie-after

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