www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to curl!

reply IntegratedDimensions <IntegratedDimensions gmail.com> writes:
Trying to curl basic stuff but std.net.curl isn't cooperating:

curl "https://www.googleapis.com/youtube/v3/channels" -G -d 
part=contentDetails -d forUsername=test -d key=somekey

import std.stdio;
import std.net.curl;


int main(string[] argv)
{
	auto http = HTTP();
	http.caInfo("cacert.pem"); // cacert.pem installed in the bin dir
	http.handle.set(CurlOption.ssl_verifypeer, 1);

	auto content = 
post("https://www.googleapis.com/youtube/v3/channels", ["part" : 
"contentDetails", "forUsername" : "test", "key" : "somekey"], 
http);


     return 0;
}

I either get the error

Unhandled exception: std.net.curl.CurlException Peer certificate 
cannot be authenticated with given CA certificates on handle at 
std\net\curl.d(4343)

or, when verifypeer is 0,

Unhandled exception: std.net.curl.HTTPStatusException HTTP 
request returned status code 404 (Not Found)

But the command line version works fine. (of course, if you want 
to test you must use a valid key and youtube user name.

This is one of the reasons I hate D ;/ I've spent more time 
trying to get std.net.curl to do something that just works from 
the command line.
May 01 2018
next sibling parent reply Dr.No <jckj33 gmail.com> writes:
On Tuesday, 1 May 2018 at 21:57:22 UTC, IntegratedDimensions 
wrote:
 Trying to curl basic stuff but std.net.curl isn't cooperating:

 curl "https://www.googleapis.com/youtube/v3/channels" -G -d 
 part=contentDetails -d forUsername=test -d key=somekey

 [...]
Just a wild guess, do you have the SSL dlls in the same folder as your executable or (less likely) in your PATH?
May 01 2018
parent reply IntegratedDimensions <IntegratedDimensions gmail.com> writes:
On Tuesday, 1 May 2018 at 22:08:50 UTC, Dr.No wrote:
 On Tuesday, 1 May 2018 at 21:57:22 UTC, IntegratedDimensions 
 wrote:
 Trying to curl basic stuff but std.net.curl isn't cooperating:

 curl "https://www.googleapis.com/youtube/v3/channels" -G -d 
 part=contentDetails -d forUsername=test -d key=somekey

 [...]
Just a wild guess, do you have the SSL dlls in the same folder as your executable or (less likely) in your PATH?
What SSL dlls? I'm sure they would be installed with whatever installation uses them. ssleay32.dll comes with dmd2 and it is in the path, if that is what you are talking about. If a dll was missing though and that was the problem then it needs to state that it is a missing dll rather than some other issue.
May 01 2018
parent reply Dr.No <jckj33 gmail.com> writes:
On Tuesday, 1 May 2018 at 22:51:01 UTC, IntegratedDimensions 
wrote:
 On Tuesday, 1 May 2018 at 22:08:50 UTC, Dr.No wrote:
 On Tuesday, 1 May 2018 at 21:57:22 UTC, IntegratedDimensions 
 wrote:
 Trying to curl basic stuff but std.net.curl isn't cooperating:

 curl "https://www.googleapis.com/youtube/v3/channels" -G -d 
 part=contentDetails -d forUsername=test -d key=somekey

 [...]
Just a wild guess, do you have the SSL dlls in the same folder as your executable or (less likely) in your PATH?
What SSL dlls?
those dlls: libeay32.dll libssl32.dll ssleay32.dll I'm sure they would be installed with whatever
 installation uses them.
I don't think so. IIRC, when I used D+curl I needed to download them manutally. This is always the case with Qt. Even using windeployqt with --webkit2 flag I still need to copy those dlls to application binary folder.
 ssleay32.dll comes with dmd2 and it is in the path, if that is 
 what you are talking about. If a dll was missing though and 
 that was the problem then it needs to state that it is a 
 missing dll rather than some other issue.
It isn't always the case if the dll is dynamic loaded, it might fail quietly, for example, if you deploy an Qt application with QWebKit missing those Open SSL dlls, an page with https protocol just doesn't open and didn't show any error at all. To find out whether some referenced dll by your executable is missing, people use Dependence Walker: http://www.dependencywalker.com/
May 01 2018
parent IntegratedDimensions <IntegratedDimensions gmail.com> writes:
On Tuesday, 1 May 2018 at 23:02:39 UTC, Dr.No wrote:
 On Tuesday, 1 May 2018 at 22:51:01 UTC, IntegratedDimensions 
 wrote:
 [...]
those dlls: libeay32.dll libssl32.dll ssleay32.dll I'm sure they would be installed with whatever
 [...]
I don't think so. IIRC, when I used D+curl I needed to download them manutally. This is always the case with Qt. Even using windeployqt with --webkit2 flag I still need to copy those dlls to application binary folder.
 [...]
It isn't always the case if the dll is dynamic loaded, it might fail quietly, for example, if you deploy an Qt application with QWebKit missing those Open SSL dlls, an page with https protocol just doesn't open and didn't show any error at all. To find out whether some referenced dll by your executable is missing, people use Dependence Walker: http://www.dependencywalker.com/
I don't think this is the problem. If I use get on https://www.google.com it works fine but if I use get on https://www.googleapis.com/youtube/v3/channels it fails so it is site dependent.
May 01 2018
prev sibling parent reply Arun Chandrasekaran <aruncxy gmail.com> writes:
On Tuesday, 1 May 2018 at 21:57:22 UTC, IntegratedDimensions 
wrote:
 Trying to curl basic stuff but std.net.curl isn't cooperating:
 This is one of the reasons I hate D ;/ I've spent more time 
 trying to get std.net.curl to do something that just works from 
 the command line.
std.net.curl is not quite up to date when compared to the curl command. It is not useful any non-trivial stuff. Right now I'm using ikod's dlang-requests[1] and I'm quite happy with it. I would recommend you to try it. [1] https://github.com/ikod/dlang-requests
May 01 2018
parent reply IntegratedDimensions <IntegratedDimensions gmail.com> writes:
On Tuesday, 1 May 2018 at 23:35:42 UTC, Arun Chandrasekaran wrote:
 On Tuesday, 1 May 2018 at 21:57:22 UTC, IntegratedDimensions 
 wrote:
 Trying to curl basic stuff but std.net.curl isn't cooperating:
 This is one of the reasons I hate D ;/ I've spent more time 
 trying to get std.net.curl to do something that just works 
 from the command line.
std.net.curl is not quite up to date when compared to the curl command. It is not useful any non-trivial stuff. Right now I'm using ikod's dlang-requests[1] and I'm quite happy with it. I would recommend you to try it. [1] https://github.com/ikod/dlang-requests
Ok, first try: Unhandled exception: object.Exception can't complete call to TLS_method at requests\ssl_adapter.d(248) which says it can't find the lib. I renamed ssleay32.dll to libssl32.dll and it then passed. I am getting http 404 error though ;/ I turned off cert though, which may be the reason, I have no idea. Seems to be working through.
May 01 2018
parent reply ikod <garry.geller gmail.com> writes:
On Wednesday, 2 May 2018 at 00:04:49 UTC, IntegratedDimensions 
wrote:
 On Tuesday, 1 May 2018 at 23:35:42 UTC, Arun Chandrasekaran 
 wrote:
 On Tuesday, 1 May 2018 at 21:57:22 UTC, IntegratedDimensions 
 wrote:
 [...]
std.net.curl is not quite up to date when compared to the curl command. It is not useful any non-trivial stuff. Right now I'm using ikod's dlang-requests[1] and I'm quite happy with it. I would recommend you to try it. [1] https://github.com/ikod/dlang-requests
Ok, first try: Unhandled exception: object.Exception can't complete call to TLS_method at requests\ssl_adapter.d(248) which says it can't find the lib. I renamed ssleay32.dll to libssl32.dll and it then passed. I am getting http 404 error though ;/ I turned off cert though, which may be the reason, I have no idea. Seems to be working through.
Did you try to use full path to cacert.pem?
May 01 2018
parent reply IntegratedDimensions <IntegratedDimensions gmail.com> writes:
On Wednesday, 2 May 2018 at 03:03:19 UTC, ikod wrote:
 On Wednesday, 2 May 2018 at 00:04:49 UTC, IntegratedDimensions 
 wrote:
 On Tuesday, 1 May 2018 at 23:35:42 UTC, Arun Chandrasekaran 
 wrote:
 [...]
Ok, first try: Unhandled exception: object.Exception can't complete call to TLS_method at requests\ssl_adapter.d(248) which says it can't find the lib. I renamed ssleay32.dll to libssl32.dll and it then passed. I am getting http 404 error though ;/ I turned off cert though, which may be the reason, I have no idea. Seems to be working through.
Did you try to use full path to cacert.pem?
That seemed to work. Why would it not look in the current directory by default? Maybe something to add?
May 02 2018
parent ikod <garry.geller gmail.com> writes:
On Wednesday, 2 May 2018 at 16:58:35 UTC, IntegratedDimensions 
wrote:
 On Wednesday, 2 May 2018 at 03:03:19 UTC, ikod wrote:
 On Wednesday, 2 May 2018 at 00:04:49 UTC, IntegratedDimensions 
 wrote:
 On Tuesday, 1 May 2018 at 23:35:42 UTC, Arun Chandrasekaran 
 wrote:
 [...]
Ok, first try: Unhandled exception: object.Exception can't complete call to TLS_method at requests\ssl_adapter.d(248) which says it can't find the lib. I renamed ssleay32.dll to libssl32.dll and it then passed. I am getting http 404 error though ;/ I turned off cert though, which may be the reason, I have no idea. Seems to be working through.
Did you try to use full path to cacert.pem?
That seemed to work. Why would it not look in the current directory by default? Maybe something to add?
Not sure about curl, but dlang-requests just pass filename as-is to libssl. I think that if you have cert file in current directiry, and use no path in call to sslSetCertFile it should work. If not - please post bugreport to github.com/ikod/dlang-requests PS. I'll check and add ssleay32 to search names for dynamic ssl library load.
May 02 2018