Skip to content

Instantly share code, notes, and snippets.

@gregyjames
Last active August 29, 2015 14:22
Show Gist options
  • Save gregyjames/d4b910b0e02602af967b to your computer and use it in GitHub Desktop.
Save gregyjames/d4b910b0e02602af967b to your computer and use it in GitHub Desktop.
Return JSON with libcurl.net
public static void Main(String[] args)
{
try {
Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);
Easy easy = new Easy();
Easy.WriteFunction wf = new Easy.WriteFunction(OnWriteData);
easy.SetOpt(CURLoption.CURLOPT_URL, args[0]);
easy.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf);
easy.Perform();
easy.Cleanup();
Curl.GlobalCleanup();
}
catch(Exception ex) {
Console.WriteLine(ex);
}
}
public static Int32 OnWriteData(Byte[] buf, Int32 size, Int32 nmemb,
Object extraData)
{
Console.Write(System.Text.Encoding.UTF8.GetString(buf));
return size * nmemb;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment