[英]Open long url using ShellExecute c++
I'm trying to open an url using ShellExecute()
. 我正在尝试使用
ShellExecute()
打开一个URL。 The url is generated by my program for a long http get request, and ShellExecute()
doesn't work and shows no responds. 该网址是由我的程序针对较长的http get请求生成的,而
ShellExecute()
无法正常工作,并且没有响应。
ShellExecute(NULL, _T("open"), url, NULL, NULL, SW_SHOWNORMAL); // Does nothing when url is too long
Than I wrote a batch file for the same command, and when the url length is greater than 259 characters it shows this error: 比我为同一命令编写了一个批处理文件,当URL长度大于259个字符时,它显示此错误:
start "" "{mywebsite}/&&&&..." // Repeating &
Windows cannot find
'{my-url}/{long-get-request} ....
Make sure you typed the name correctly, and then try again.
Any idea for extending the character limit for ShellExecute()
? 任何扩展
ShellExecute()
的字符限制的想法吗? Or maybe a cool solution to open a long url besides ShellExecute()
or system()
or System::Diagnostics::Process::Start()
, they all fail to work. 也许是一个很棒的解决方案,除了
ShellExecute()
或system()
或System::Diagnostics::Process::Start()
之外,还可以打开一个长URL,它们都无法正常工作。
I guess I have a solution, but it's probably not the best solution. 我想我有一个解决方案,但这可能不是最佳解决方案。 Basically, I create an html file that redirects to my long url.
基本上,我创建了一个html文件,该文件重定向到我的长URL。
private: Void showPage(const string& httpGetString) {
string url = "{my-website}?" + httpGetString;
remove("jumper.html");
string htmlJumper = "<html><meta http-equiv=\"refresh\" content=\"0; url=" + url + "\"</html>";
fstream jumperFile;
jumperFile.open("jumper.html", ios::out);
jumperFile << htmlJumper;
jumperFile.close();
ShellExecute(NULL, _T("open"), L"jumper.html", NULL, NULL, SW_SHOWNORMAL);
}
The suggestion for copying the link in to *.html file will work, however ShellExecute
will run the program associated with *.html
not http:
. 将链接复制到* .html文件的建议将起作用,但是
ShellExecute
将运行与*.html
关联的程序,而不是http:
*.html
In theory those associations can be different. 从理论上讲,这些关联可以不同。 If you don't care, then just find the association with
*.html
and use CreateProcess
as follows: 如果您不在乎,则只需查找与
*.html
的关联,并按如下所示使用CreateProcess
:
std::wstring url = L"http://localhost/fake.php?123";
wchar_t buf[MAX_PATH] = { 0 };
DWORD size = _countof(buf);
AssocQueryString(0, ASSOCSTR_EXECUTABLE, L".html", 0, &buf[0], &size);
std::wstring cmd(buf);
cmd += L" ";
cmd += url;
PROCESS_INFORMATION pi;
STARTUPINFO si{ sizeof(si) };
CreateProcess(0, &cmd[0], 0, 0, FALSE, NORMAL_PRIORITY_CLASS, 0, 0, &si, &pi);
...
In Windows 10 ShellExecute
accepts large argument lines. 在Windows 10中,
ShellExecute
接受较大的参数行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.