C++ DLL 中的 CPR GET 请求在执行时出现问题
我有一个自定义 CSP dll,它必须向 API 发出 GET 请求。我正在向 CPR 库发出请求,但是当我进行此调用时,程序挂起。
auto r = cpr::Get(cpr::Url{ URL });
我正在使用加载库并调用导出方法的控制台应用程序进行测试。
我正在使用 Visual Studio dll 项目进行开发,并从 vcpkg 收集依赖项。
如果我从控制台应用程序发出此调用,它会工作,但是当我从 DLL 发出请求时,它会挂起并且连接永远不会完成。
我一直在尝试其他库来发出请求,当我尝试调用端点时,所有库都挂起。
提前致谢!
编辑:
如果我在像这样的控制台应用程序中发出请求,它会起作用
BOOL Authenticate() {
auto r = cpr::Get(cpr::Url{ URL });
long sc = r.status_code;
if (sc != 200) {
return FALSE;
}
return TRUE;
}
int main()
{
if (Authenticate()) {
return 0;
}
else {
return -1;
}
}
问题是,如果我向从 dll 导出的相同方法发出请求,则在 GET 请求完成时它会挂起。该dll是用Visual Studio编译的-> dll 项目。此处示例,其中方法authenticate 是前面示例中的a。
int main()
{
HINSTANCE hinstDLL;
hinstDLL = LoadLibrary(PATH_TO_DLL);
if (!hinstDLL)
printf("LoadLibrary error %x\n", GetLastError());
else {
Authenticate_DLL lpproc;
lpproc = (CPAcquireContext_DLL)GetProcAddress(hinstDLL, "Authenticate");
if (!lpproc())
{
printf("LoadMethod error %x\n", GetLastError());
}
}
}
URL 是一个 REST API,在远程服务器中没有完成任何请求,因此 CPR 不会进行调用
EDIT2:
经过大量测试后,只有当我使用 HTTPS URL 时,请求才会挂起。如果 URL 只是 HTTP,则请求已完成
I have a custom CSP dll that has to make a GET request to an API. I am making the request with CPR library, but when I make this call the program hangs.
auto r = cpr::Get(cpr::Url{ URL });
I am testing with a console application loading the library and calling to the exported method.
I´m developing with Visual Studio dll project and I collect the dependencies from vcpkg.
If I make this call from the console application it works, but when I make the request from the DLL it hangs and connection is never done.
I have been trying other libraries for making the request and all of them hang when I try to make the call to the endpoint.
Thanks in advance!
EDIT:
If I make the request in a console application like this it works
BOOL Authenticate() {
auto r = cpr::Get(cpr::Url{ URL });
long sc = r.status_code;
if (sc != 200) {
return FALSE;
}
return TRUE;
}
int main()
{
if (Authenticate()) {
return 0;
}
else {
return -1;
}
}
The problem is that if I make the request to the same method exported from a dll it hangs when the GET request is done. The dll is compiled with Visual Studio -> dll project. Sample here, where method authenticate is a is in previous example.
int main()
{
HINSTANCE hinstDLL;
hinstDLL = LoadLibrary(PATH_TO_DLL);
if (!hinstDLL)
printf("LoadLibrary error %x\n", GetLastError());
else {
Authenticate_DLL lpproc;
lpproc = (CPAcquireContext_DLL)GetProcAddress(hinstDLL, "Authenticate");
if (!lpproc())
{
printf("LoadMethod error %x\n", GetLastError());
}
}
}
URL is a REST API and in remote server no request is done, so CPR is not making the call
EDIT2:
After a lot of testing requests only hang when I make use of HTTPS URLs. If the URL is just HTTP the request is done
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论