URLDownloadToFile 失败,0x800c0008 (INET_E_DOWNLOAD_FAILURE) 取决于 URL 的长度 [英] URLDownloadToFile fails with 0x800c0008 (INET_E_DOWNLOAD_FAILURE) depending on length of URL

查看:117
本文介绍了URLDownloadToFile 失败,0x800c0008 (INET_E_DOWNLOAD_FAILURE) 取决于 URL 的长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道

有没有办法使用 URLDownloadToFile 下载长度超过 2084 个字符的 URL?

解决方案

WinInet 的 INTERNET_MAX_URL_LENGTH 常量正好是 2084,包括一个空终止符.

另请参阅您可以传递给 Wininet 函数 HttpOpenRequest 的最大 URL 长度是多少? 的其他各种问题的答案与网址相关的限制.

如果您需要下载更长的 URL,则必须使用另一个 HTTP 客户端库.

I'm aware there is a similar question here. However my symptoms differ. There seems to be some kind of URL length restriction in place that I couldn't find documented. The limit seens to be 2084 (sic! not 2048!) characters in the URL. The easiest repro is just a console application with this code:

#include "stdafx.h"
#include "urlmon.h"
#pragma comment(lib, "urlmon")


int main()
{
    HRESULT hr = URLDownloadToFile(NULL,L"http://www.google.de/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png?oids=1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890",
        L"c:\\temp\\x.png",
        0,
        NULL);

    return 0;
}

Of course, the URL doesn't make actual sense, in my real life example these are important parameters. As soon as I shorten the URL below 2084 characters, I get back S_OK and everything is fine.

I used Fiddler to check the request which tells me I'm seeing http status code 200 (OK) for the download and even the server response is just perfect:

Is there any way to download URLs longer than 2084 characters using URLDownloadToFile?

解决方案

WinInet's INTERNET_MAX_URL_LENGTH constant is exactly 2084, including a null terminator.

Also see the answers to What is the maximum URL length you can pass to the Wininet function, HttpOpenRequest? for various other URL-related limits.

If you need to download a longer URL, you will have to use another HTTP client library.

这篇关于URLDownloadToFile 失败,0x800c0008 (INET_E_DOWNLOAD_FAILURE) 取决于 URL 的长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆