我在Windows 7 x64上的mingw64(msys2)从下面的链接中编写了简单的libcurl示例程序,x64
不幸的是,它给了我错误:
curl_easy_perforf()失败:SSL CA CERT(路径访问权限?)
i 的问题试图重新安装MSYS2中的开放SSL证书,但无济于事。
请记住,我是一个拥有SSL和证书的菜鸟!但是我需要以便携式方式在C中进行HTTPS请求,因此我被迫使用libcurl。
我认为我的系统没有任何问题,因为1。使用wininet发送的HTTPS请求。H可以完美地运行2。我可以将https请求带有curl 命令而没有任何问题。
PS。如果这里有类似的话题,我深表歉意,但是据我所知,在这种特定情况下,没有一个人能解决相同的问题
吗?
I compiled the simple libcurl example program from the link below with mingw64 (MSYS2) on Windows 7 x64
https://curl.se/libcurl/c/simple.html
Unfortunately it gives me the error:
curl_easy_perform() failed: Problem with the SSL CA cert (path? access rights?)
I tried to reinstall the open ssl certificates in MSYS2 to no avail.
Please keep in mind that I am a total noob with SSL and certificates! But I need to do an HTTPS request in C in a portable way so I was forced to use libcurl.
I don't think there is anything wrong with my system, since 1. an https request sent using WinInet.h works perfectly 2. I can send https requests with the cUrl command without any issues.
PS. I apologize if there are similar topics here, but as far as I could see, none of them addresses the same problem in this specific scenario
Any idea ?
发布评论
评论(2)
我正在回答自己的问题,因为我最终设法解决了这个问题,希望这个问题对别人有用。实际上,这似乎是一个普遍的问题,尽管我可以发现它清楚地解决了新手(像我一样)。
问题是由基于openssl的libcurl引起的。 OpenSSL是Unix/Linux的东西,除非一个人明确安装Windows(未测试),否则无法在Windows上工作。但是,就像我的情况下一样,人们可能不想强迫其软件的用户安装任何其他组件,例如OpenSSL。
该解决方案是建立一个不是基于OpenSSL而是在Windows SSPI上的Libcurl,或者找到合适的Libcurl软件包。经过多次努力和搜索后,我发现MSYS2存在这样的包装,它是mingw curl winssl:
https://packages.msys2.org/package/prackage/mingw-w64-x86_64-curl-winssl?repo=mingmingmw64
足以安装它
:可能会很麻烦,看来并非所有依赖项都清楚地列出了(似乎是一个已知的错误)。 ,如果在我的情况下使用IDE,并且对Linux Commandline一无所知(我正在使用Code :: Blocks),则有必要链接到以下libs:
and
#define curl_staticlib
(强制性)特别是 我必须说的最后一个说明,恕我直言libcurl应该基于默认情况下的Windows,而不是在任何MingW发行版中基于OpenSSL,因为它们被认为它们在Windows下工作并产生Windows可执行文件 - 但是出于某些原因,我似乎并不蒙蔽,这似乎不是总是这样。
I am answering my own question since in the end I managed to solve the problem, and in the hope this question can be useful to somebody else. It actually seems a common problem, despite nowhere I could find it addressed clearly and for newbies (like me).
The problem is caused by libcurl being based on openSSL. OpenSSL is a Unix/Linux thing and cannot work on Windows unless one install the openSSL for Windows explicitly (not tested). But one may not want to force the users of his/her software to install any additional components like openSSL - as in my case.
The solution is building a libcurl NOT based on openSSL but on windows SSPI, or finding a suitable libcurl package. After many efforts and searching, I discovered that such a package existed for MSYS2, it is mingw curl winssl:
https://packages.msys2.org/package/mingw-w64-x86_64-curl-winssl?repo=mingw64
It was enough to install it:
Linking statically with libcurl can be troublesome and it looks like not all dependencies are listed clearly (seems a known bug). In particular if using an IDE like in my case and knowing nothing of Linux commandline (I am using Code::Blocks) it is necessary to link against the following libs:
and
#define CURL_STATICLIB
(mandatory)As a last note I must say that IMHO libcurl should be based on Windows by default, not on openSSL, in any minGW distributions, since they are thought to work under Windows and produce Windows executables - but for some reasons obscure to me, this seems not always the case.
您可以从 https://curl.sese https://curl.sesese /docs/caextract.html 并在您的程序中使用它:
You can get certificate file named cacert.pem from https://curl.se/docs/caextract.html and use it in your program like this: