[英]Open long url using ShellExecute c++
我正在嘗試使用ShellExecute()
打開一個URL。 該網址是由我的程序針對較長的http get請求生成的,而ShellExecute()
無法正常工作,並且沒有響應。
ShellExecute(NULL, _T("open"), url, NULL, NULL, SW_SHOWNORMAL); // Does nothing when url is too long
比我為同一命令編寫了一個批處理文件,當URL長度大於259個字符時,它顯示此錯誤:
start "" "{mywebsite}/&&&&..." // Repeating &
Windows cannot find
'{my-url}/{long-get-request} ....
Make sure you typed the name correctly, and then try again.
任何擴展ShellExecute()
的字符限制的想法嗎? 也許是一個很棒的解決方案,除了ShellExecute()
或system()
或System::Diagnostics::Process::Start()
之外,還可以打開一個長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);
}
將鏈接復制到* .html文件的建議將起作用,但是ShellExecute
將運行與*.html
關聯的程序,而不是http:
*.html
從理論上講,這些關聯可以不同。 如果您不在乎,則只需查找與*.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);
...
在Windows 10中, ShellExecute
接受較大的參數行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.