<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: dl=1 option error in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/dl-1-option-error/m-p/543587#M25994</link>
    <description>&lt;P&gt;Can you elaborate on what you mean when you say "it doesn't work"? What unexpected error or output are you getting?&lt;/P&gt;</description>
    <pubDate>Tue, 07 Sep 2021 14:56:46 GMT</pubDate>
    <dc:creator>Greg-DB</dc:creator>
    <dc:date>2021-09-07T14:56:46Z</dc:date>
    <item>
      <title>dl=1 option error</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/dl-1-option-error/m-p/543479#M25991</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Until recently, I downloaded a file using the dl=1 parameter in my C++ code.&lt;/P&gt;
&lt;P&gt;ex) &lt;A href="https://www.dropbox.com/{private_url}?dl=1" target="_blank" rel="noopener"&gt;https://www.dropbox.com/{private_url}?dl=1&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But now it doesn't work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If use Python's requests module with the same URL, it will work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And when you call another URL(not dropbox) with the corresponding C++ code, it is worked.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is my code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;#include &amp;lt;iostream&amp;gt;
#include &amp;lt;Windows.h&amp;gt;

#ifndef DEFINE_WIN_HTTP
#define DEFINE_WIN_HTTP 1
#include &amp;lt;Winhttp.h&amp;gt;
#pragma comment (lib, "winhttp.lib")
#endif

#define BUFFER_SIZE 4096

int main()
{
	WCHAR szUrl[] = L"https://www.dropbox.com/{private_url}?dl=1";
	BYTE response[4096];

	HINTERNET      hSession, hConnect, hRequest;
	URL_COMPONENTS urlComponents;
	WCHAR          szHostName[256], szUrlPath[2048];
	DWORD          dwSize;
	DWORD          dwStatusCode;

	hSession = WinHttpOpen(L"sample", WINHTTP_ACCESS_TYPE_AUTOMATIC_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0);
	if (hSession == NULL)
		return -1;

	ZeroMemory(&amp;amp;urlComponents, sizeof(URL_COMPONENTS));
	urlComponents.dwStructSize = sizeof(URL_COMPONENTS);
	urlComponents.lpszHostName = szHostName;
	urlComponents.dwHostNameLength = sizeof(szHostName) / sizeof(WCHAR);
	urlComponents.lpszUrlPath = szUrlPath;
	urlComponents.dwUrlPathLength = sizeof(szUrlPath) / sizeof(WCHAR);



	if (!WinHttpCrackUrl(szUrl, lstrlenW(szUrl), 0, &amp;amp;urlComponents)) {
		WinHttpCloseHandle(hSession);
		return -2;
	}

	hConnect = WinHttpConnect(hSession, szHostName, INTERNET_DEFAULT_PORT, 0);
	if (hConnect == NULL) {
		WinHttpCloseHandle(hSession);
		return -3;
	}

	hRequest = WinHttpOpenRequest(hConnect, L"GET", szUrlPath, NULL, WINHTTP_NO_REFERER, WINHTTP_DEFAULT_ACCEPT_TYPES, 0);
	if (hRequest == NULL) {
		WinHttpCloseHandle(hConnect);
		WinHttpCloseHandle(hSession);
		return -4;
	}

	if (!WinHttpSendRequest(hRequest, WINHTTP_NO_ADDITIONAL_HEADERS, 0, WINHTTP_NO_REQUEST_DATA, 0, 0, 0)) {
		WinHttpCloseHandle(hRequest);
		WinHttpCloseHandle(hConnect);
		WinHttpCloseHandle(hSession);
		return -5;
	}

	WinHttpReceiveResponse(hRequest, NULL);

	dwSize = sizeof(DWORD);
	WinHttpQueryHeaders(hRequest, WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER, WINHTTP_HEADER_NAME_BY_INDEX, &amp;amp;dwStatusCode, &amp;amp;dwSize, WINHTTP_NO_HEADER_INDEX);
	if (dwStatusCode == HTTP_STATUS_OK)
	{
		if (!WinHttpQueryDataAvailable(hRequest, &amp;amp;dwSize))
			printf("Error %u in WinHttpQueryDataAvailable.\n",
				GetLastError());

		ZeroMemory(response, dwSize + 1);
		WinHttpReadData(hRequest, response, sizeof(BYTE) * BUFFER_SIZE, NULL);
	}
	else {
		TCHAR szBuf[256];
		wsprintf(szBuf, TEXT("Status Code %d"), dwStatusCode);
	}

	WinHttpCloseHandle(hRequest);
	WinHttpCloseHandle(hConnect);
	WinHttpCloseHandle(hSession);

	std::string response_string = std::string((char*)response);
	std::cout &amp;lt;&amp;lt; response_string;

	return 0;
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Sep 2021 09:56:10 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/dl-1-option-error/m-p/543479#M25991</guid>
      <dc:creator>Hail-Kang</dc:creator>
      <dc:date>2021-09-08T09:56:10Z</dc:date>
    </item>
    <item>
      <title>Re: dl=1 option error</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/dl-1-option-error/m-p/543587#M25994</link>
      <description>&lt;P&gt;Can you elaborate on what you mean when you say "it doesn't work"? What unexpected error or output are you getting?&lt;/P&gt;</description>
      <pubDate>Tue, 07 Sep 2021 14:56:46 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/dl-1-option-error/m-p/543587#M25994</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2021-09-07T14:56:46Z</dc:date>
    </item>
  </channel>
</rss>

