masroore / curlsharp Goto Github PK
View Code? Open in Web Editor NEWCurlSharp - .Net binding and object-oriented wrapper for libcurl.
License: BSD 3-Clause "New" or "Revised" License
CurlSharp - .Net binding and object-oriented wrapper for libcurl.
License: BSD 3-Clause "New" or "Revised" License
Hello,
I am trying to access a URL which requires client authentication.
But, the certificate/private key are stored on a smart card.
I have no idea how to proceed !?
Github doesn't provide a good way that I know of to say thank you, but holy smokes, THANK YOU. Curlsharp is amazing, doubly so due to the wonderful examples directory. You totally rock. <3
libcurl in multi-thread will coredump if enabled signal support(libcurl internal use signal to implemented dns query timeout timer), will coredump, because signal mechanism in multi-thread Situation behavior is undefined!
this will lost dns query timeout function, but we can suggest user compiled c-ares support libcurl to restore dns query timeout function.
Just a suggesstion :-)
Even setting the parameters works and does not work. I think it should work interchangeably so and so.
//easy.UserAgent = "Do UserAgent"; // Works
easy.SetOpt(CurlOption.UserAgent, "Do UserAgent SetOpt"); // Does not work
//easy.Proxy = "xxx.xxx.xxx.xxx:21320"; // Works
easy.SetOpt(CurlOption.Proxy, "xxx.xxx.xxx.xxx:21320"); // Does not work
//easy.PostFields = postData; // Works :)
easy.SetOpt(CurlOption.PostFields, postData); // Does not work
//easy.Encoding = "gzip, deflate"; // Works
easy.SetOpt(CurlOption.Encoding, "gzip, deflate"); // Does not work
easy.FollowLocation = true; // Works or
easy.SetOpt(CurlOption.FollowLocation, true); // Works
At the time, please check yourself
Is there a way to do basic authentication with this library ? If so, then how?
i am use your CurlSharp's sample
all is ok but "MultiDemo" always wrong ,
line 49 : var rc = multi.Select(1000); // one second alway return -1
waiting for your help!
Error "SslCaCert" all https site
sample site
https://www.google.com/
https://www.whatismyreferer.com/
https://www.facebook.com/
First of all my apologies; This is not an issue.
I am trying to execute veracode api using curlSharp library. Manually I can execute the command as below.
curl --compressed -u [veracodeuser]:[mypassword] https://analysiscenter.veracode.com/api/4.0/getapplist.do -F 'include_user_info=true'
using (var easy = new CurlEasy())
{
easy.UserPwd = "Password"
easy.AutoReferer = true;
easy.FollowLocation = true;
easy.Url = textBoxUrl.Text.Trim();
easy.WriteFunction = OnWriteData;
easy.Perform();
}
I couldn't figure out how to pass username and --compressed -F options. Could you please let me know if I can accomplish this with CurlSharp.
I appreciate your response.
The POST method not working CurlSharp. The same does not operate
easy.PostFields> FileUpload.cs not working
easy.HttpPost> BookPost.cs not working
64 Bit
can you write or update an example to write data downloaded to harddisk.
Thanks
Projects compiled ok. When running, for example, upload.exe, get the following message:
System.DllNotFoundException: Unable to load DLL 'libcurl64.dll': The specified module could not be found.
Need to be able to upload a file from a local machine to a location on a server, so ftp upload seems to be the obvious. Need to do it in C#, as part of a larger program.
Thanks very much for any help.
MultiDemo run
allways console write "CurlMulti.Select() returned -1";
Hello,
I thought I would make my happiness with CurlSharp, but I have struggled for 3 days.
Unable to launch the project. An error appears when loading the LibCurl.dll dll on the _initCode = NativeMethods.curl_global_init ((int) flags)
instruction;
For information, I am using Windows 10 version 1809 64 bits and I am loading the solution with Visual Studio 2019
At first, I have an error: libcurl not found
After copying libcurl.dll to the System32 directory I have a System.BadImageFormatException exception
I also copied the DLLs from CurlSharp \ libs \ i386 to CurlSharp \ Samples \ bin as shown in issues # 36 but it's not better.
Has anyone ever had this problem and found a solution?
any one can help me out with curl ssl 2 way communication.
using the below code snippet
using (var easy = new CurlEasy())
{
easy.AutoReferer = true;
easy.FollowLocation = true;
easy.Url = textBoxUrl.Text.Trim();
easy.CaInfo = @"------------.crt-----------------------------";
easy.CaPath = @"----------------.crt-------------------------";
easy.SslKey = @"-----------.key------------------------------";
easy.SslCert = @"----------------.crt-------------------------";
easy.WriteFunction = OnWriteData;
easy.Perform();
}
provide me any example c# code for curl ssl 2 way communication
getting below error
"Unknown CA (48)"
Thanks.
Hello again. It does not work to send a file or send wrong? My test C# code:
string avatar = Application.StartupPath + @"\avatary\myface.jpg";
var mf = new CurlHttpMultiPartForm();
mf.AddSection(CurlFormOption.CopyName, "parm1", CurlFormOption.CopyContents, "value1", CurlFormOption.End);
mf.AddSection(CurlFormOption.CopyName, "parm2", CurlFormOption.CopyContents, "value2", CurlFormOption.End);
if (File.Exists(avatar))
{
mf.AddSection(CurlFormOption.CopyName, "uploadedfile", CurlFormOption.File, avatar, CurlFormOption.ContentType, "application/application/binary", CurlFormOption.End);
Console.WriteLine(avatar);
}
easy.HttpPost = mf;
My OUT:
Array
(
[parm1] => value1
[parm2] => value2
)
Array
(
)
Host: www.testsite.com
Connection: close
Content-Length: 246
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:22.0) Gecko/20100101 Firefox/22.0
Accept-Encoding: gzip,deflate
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
Accept-Language: pl,en-us;q=0.7,en;q=0.3
Cache-Control: max-age=0
Pragma: no-cache
Content-Type: multipart/form-data; boundary=------------------------e489e380b38b4322
Hi, I was trying to use your library for TLS 1.2 https (ssl) requests. However, I could not find CURL_SSLVERSION_TLSv1_2 defined in in the calling c# wrapper. Could you pl give some inputs or pointers in this regard to make it work for TLS 1.2 Thanks.
I would like to retrieve the Server certificate, I expected CertInfo to be the solution but seems it is missing
Hello,
currently it seems like TLS errors aren't handled in any way.
If I connect to a host with invalid certificate Perform() returns OK error code but the resulting document is empty.
CurlEasy.ErrorBuffer is also always empty.
It seems like it's never initialized and the set method looks like it's not correctly used.
https://curl.haxx.se/libcurl/c/CURLOPT_ERRORBUFFER.html
when I second times call this method, old saved _curlWriteData not call freeHandle() to free, It trigger GC memory leak
CurlSharp\Samples\WinSamples\WinSamples.csproj
this project missing libcurl.dll
When I copy the libcurl.dll from CurlSharp\libs\i386
still can not load the dll
Hi!
I'm getting UnsupportedProtocol when trying to make a request that uses CurlSharp like this:
CurlSharp.Curl.GlobalInit(CurlInitFlag.All);
using (var easy = new CurlEasy())
{
easy.WriteFunction = OnWriteData;
easy.PostFields = postData;
var header = new CurlSlist();
header.Append("ContentType: application/x-www-form-urlencoded");
easy.SetOpt(CurlOption.HttpHeader, header);
easy.PostFieldSize = postData.Length;
easy.UserAgent = "Test-Agent";
easy.FollowLocation = true;
easy.Url = authurl;
easy.Post = true;
curlcode = easy.Perform();
responseCode = easy.ResponseCode;
}
CurlSharp.Curl.GlobalCleanup();
the authurl is a https SSL/TLS url...
What is wrong?
Thanks
Please ignore the Chinese message.
I'v tried 0.5.0 and 0.5.1 with Visual Studio 2017. And it works great.
But with the 2017/08/10 build... Error occurred at NativeMethods.
System.TypeInitializationException: 'CurlSharp.NativeMethods' 的類型初始設定式發生例外狀況。 ---> System.DllNotFoundException: 無法載入 DLL 'api-ms-win-core-sysinfo-l1-2-0.dll': 找不到指定的模組。 (發生例外狀況於 HRESULT: 0x8007007E)
於 Interop.mincore.GetNativeSystemInfo(SYSTEM_INFO& lpSystemInfo)
於 System.Runtime.InteropServices.RuntimeInformation.get_OSArchitecture()
於 CurlSharp.NativeMethods..cctor()
--- 內部例外狀況堆疊追蹤的結尾 ---
When i post a curl url i was facing this strange issue
message
{"Object contains non-primitive or non-blittable data."}
at System.Runtime.InteropServices.GCHandle.InternalAlloc(Object value, GCHandleType type)
at System.Runtime.InteropServices.GCHandle.Alloc(Object value, GCHandleType type)
at CurlSharp.CurlEasy.getHandle(Object obj) in d:\sharedfiles\Jagan\CurlSharp-master\CurlSharp-master\CurlSharp\CurlEasy.cs:line 1526
at CurlSharp.CurlEasy.setReadData(Object data) in d:\sharedfiles\Jagan\CurlSharp-master\CurlSharp-master\CurlSharp\CurlEasy.cs:line 252
at CurlSharp.CurlEasy.set_ReadData(Object value) in d:\sharedfiles\Jagan\CurlSharp-master\CurlSharp-master\CurlSharp\CurlEasy.cs:line 330
at Upload.Upload.Main(String[] args) in d:\sharedfiles\Jagan\CurlSharp-master\CurlSharp-master\Samples\Upload\Upload.cs:line 36
Curl command is
curl -i -X POST -H "Content-Type: multipart/form-data" -H "Authorization: SIMPLE Y2F0Y2h0aGVtb21lbjpjYXRjaHRoZW1vbWVudDExMQ==" -F "card={"text":"sometext", "userName":"%USERNAME%", "screenName":"screenName", "avatarUrl":"https://www.google.com/images/srpr/logo11w.png\"};type=application/json" -F "pic=@c:\users\my\desktop\download.jpg" "https://socialwall.cvent.com/livestream/api/event/395b4759-8b93-4fb1-b33b-387c3928c1ca/socialpost" -v
below code is my implementation of above curl command
public static void Main(String[] args)
{
try
{
string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "download.jpg");
Curl.GlobalInit(CurlInitFlag.All);
using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
{
string _cred = string.Format("{0} {1}", "SIMPLE", "Y2F0Y2h0aGVtb21lbjpjYXRjaHRoZW1vbWVudDExMQ==");
string url = "https://socialwall.cvent.com/livestream/api/event/395b4759-8b93-4fb1-b33b-387c3928c1ca/socialpost";
var card = new Card
{
text = "Ohmygod",
userName = "CatchTheMoment",
screenName = "Socialpost",
avatarUrl = "https://www.google.com/images/srpr/logo11w.png"
};
var jsonstring = Newtonsoft.Json.JsonConvert.SerializeObject(card);
using (var easy = new CurlEasy())
{
easy.ReadFunction = OnReadData;
easy.ReadData = fs;
var headers = new CurlSlist();
headers.Append("Content-Type: multipart/form-data");
headers.Append("Accept: */*");
headers.Append("user-agent:Mozilla/4.0");
headers.Append("Authorization0:"+_cred);
headers.Append("Except: 100-continue");
easy.HttpHeader = headers;
easy.DebugFunction = OnDebug;
easy.SetOpt(CurlOption.Verbose, true);
easy.SetOpt(CurlOption.Header, true);
easy.ProgressFunction = OnProgress;
easy.Url = url;
easy.Upload = true;
easy.InfileSize = fs.Length;
easy.PostFields = "card="+jsonstring;
easy.PostFieldSize = jsonstring.Length;
easy.Perform();
Console.ReadLine();
}
}
Curl.GlobalCleanup();
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
public static Int32 OnReadData(Byte[] buf, Int32 size, Int32 nmemb, Object extraData)
{
var fs = (FileStream) extraData;
return fs.Read(buf, 0, size*nmemb);
}
public static void OnDebug(CurlInfoType infoType, String msg, Object extraData)
{
Console.WriteLine(msg);
}
public static Int32 OnProgress(Object extraData, Double dlTotal,
Double dlNow, Double ulTotal, Double ulNow)
{
Console.WriteLine("Progress: {0} {1} {2} {3}",
dlTotal, dlNow, ulTotal, ulNow);
return 0; // standard return from PROGRESSFUNCTION
}
public class Card
{
public string text { get; set; }
public string userName { get; set; }
public string screenName { get; set; }
public string avatarUrl { get; set; }
}
I read another Issues and try the solutions...
Before all... Am using Windows 10 x64 operating System.
I am trying to run WinSamples, I already target to x86 and Debug my solution. When I start the project the Form appears and when I click on "Get Source" Button I receive the next error:
System.DllNotFoundException: 'Can't load the file DLL 'libcurl': Can't find specified module. (Exception of HRESULT: 0x8007007E)'
So copy the DLL from the folder libs/i386/libcurl.dll and paste inside WinSamples/bin/Debug and start the program again. But I get the same error.
I try including the dll on the project.... copy all the others dll files from i386
What else can I do? What I am doing wrong? Thanks in advance
Hi,
I want to wrap my native curl call
curl.exe -i -Uuser:token -O "http://path/to/file.zip"
using CurlSharp.
First question:
Do I have to set user and token by
easy.UserAgent = "user";
easy.UserPwd = "token";
in CurlSharp?
Second question:
Can you give an example on how to modify OnWriteData
to handle my zip file.
Thanks a lot!
Hello again, faced a problem on Linux Mono 3.0 CurlEasy causes a large memory leak.
My test code:
public static void DoTestCurlEasy()
{
bool wykonuj = true;
int nrpetli = 0;
while (wykonuj)
{
using (var easy = new CurlEasy())
{
easy.Url = "http://www.xxxxxxx.com/dotest.html";
easy.WriteData = null;
easy.WriteFunction = OnWriteData;
easy.Perform();
}
Console.WriteLine("nrpetli: {0}", nrpetli);
nrpetli++;
Thread.Sleep(200);
}
}
public static Int32 OnWriteData(Byte[] buf, Int32 size, Int32 nmemb, Object extraData)
{
//var userData = (string)extraData;
//Console.Write(Encoding.UTF8.GetString(buf));
return size * nmemb;
}
Linux htop
Running is 0.9 MEM%
Are there any plans to support multi setopt?
The documentation on multi transfers indicates that curl_multi_info_read
should be called to retrieve the status of completed transfers.
I cannot for the life of me get this to work (my thread appears to hang), so I'd love an example that uses it.
Many, many thanks!
~ Paul
the default file name can not load curl lib on ubuntu 16.04
private const string LIBCURL = "libcurl";
this works
private const string LIBCURL = "libcurl.so.3";
can i change the headers order ?
when i use upload sample,i get error:
Object 包含非基元或非直接复制到本机结构中的数据。
Object contains non-primitive or non-blittable data. (Parameter 'value')
after i add : easy.SetOpt(CurlOption.HttpHeader, "content - type = audio / x - raw");
error occur again
thanks
This is a pretty awesome wrapper, would be great to see it support libcurl 7.52 and a the curlmopt_XXX for enabling full HTTP/2
Hi,
I have been using the CurlSharp Library for some time now and Ive noticed I get a response code of 200 on a successful HttpGet. I am a bit confused as to what this means exactly other than(from what I can Guess) is the HTTPGET was successful.
I have looked at the enums but haven't found any 200.
do you mind explaining it?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.