string - 下载字符串 C++ 返回空
问题描述
我一直在使用我在互联网上找到的这个下载字符串函数,它一直没有返回任何内容。有任何想法吗?
std::string replaceAll(std::string subject, const std::string& search,
const std::string& replace) {
size_t pos = 0;
while ((pos = subject.find(search, pos)) != std::string::npos) {
subject.replace(pos, search.length(), replace);
pos += replace.length();
}
return subject;
}
std::string DownloadString(std::string URL) {
HINTERNET interwebs = InternetOpenA("Mozilla/5.0", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, NULL);
HINTERNET urlFile;
std::string rtn;
if (interwebs) {
urlFile = InternetOpenUrlA(interwebs, URL.c_str(), NULL, NULL, NULL, NULL);
if (urlFile) {
char buffer[2000];
DWORD bytesRead;
do {
InternetReadFile(urlFile, buffer, 2000, &bytesRead);
rtn.append(buffer, bytesRead);
memset(buffer, 0, 2000);
} while (bytesRead);
InternetCloseHandle(interwebs);
InternetCloseHandle(urlFile);
std::string p = replaceAll(rtn, "|n", "\r\n");
return p;
}
}
InternetCloseHandle(interwebs);
std::string p = replaceAll(rtn, "|n", "\r\n");
return p;
}
std::string str = DownloadString("127.0.0.1/document.txt");
std::cout << str << std::endl;
我已经尝试清除我的网址的缓存,但没有任何效果。
解决方案
推荐阅读
- c# - 使用“AutoMapper”将一个包含类列表的类映射到另一个类似属性的类中
- excel-formula - 自定义舍入规则
- ios - ios 应用程序中是否有显示音频/图像/视频的选择器?
- c# - Xamarin 表单上的按键事件
- python - 使用 python 解码 Alt 代码
- sql - 如何将 CTE 的结果插入到某些列具有恒定值的表中
- c# - 无法将反序列化 Json 对象绑定到类模型中
- python - 为什么我在 github 上的 python 包没有显示 used by 信息?
- python - ValueError:检查输入时出错:预期 left_input 的形状为 (134,),但得到的数组的形状为 (1,)
- image - 如何找到图像中点之间的距离?