Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

How to download a file from a URL in C, as a browser would?

Use libcurl, and see this examples page.

If you want to get it to work, make it work with the command line curl too, and use the --libcurl option. I suspect the problem might be more to do with javascript, cookies, a login or whatever. All these are soluble, but play with the command line to get it to work. My diagnosis here is that your URL is missing .com after yahoo.

For instance:

curl --silent --libcurl /tmp/test.c

produces the output to screen:


and produces the code:

/********* Sample code generated by the
curl command line tool **********
 * All curl_easy_setopt() options are documented
#include <curl/curl.h>

main (int argc, char *argv[])
  CURLcode ret;
  CURL *hnd;

  hnd = curl_easy_init ();
  curl_easy_setopt (hnd, CURLOPT_URL,
  curl_easy_setopt (hnd, CURLOPT_NOPROGRESS, 1L);
  curl_easy_setopt (hnd, CURLOPT_USERAGENT,
  curl_easy_setopt (hnd, CURLOPT_MAXREDIRS, 50L);
  curl_easy_setopt (hnd, CURLOPT_TCP_KEEPALIVE,

  /* Here is a list of options the curl code used
that cannot get generated
     as source easily. You may select to either
not use them or implement
     them yourself.

     CURLOPT_WRITEDATA set to a objectpointer
     CURLOPT_READDATA set to a objectpointer
     CURLOPT_READFUNCTION set to a functionpointer
     CURLOPT_SEEKDATA set to a objectpointer
     CURLOPT_SEEKFUNCTION set to a functionpointer
     CURLOPT_ERRORBUFFER set to a objectpointer
     CURLOPT_STDERR set to a objectpointer
     CURLOPT_HEADERDATA set to a objectpointer


  ret = curl_easy_perform (hnd);

  curl_easy_cleanup (hnd);
  hnd = NULL;

  return (int) ret;

/**** End of sample code ****/

Categories : C

Related to : How to download a file from a URL in C, as a browser would?
PHP - How to send textarea value with JavaScript AJAX and output it as .txt file for browser to download?
Maybe you should clean the buffer while (@ob_end_clean()); ob_start(); header("Content-Type: text/plain"); header('Content-Disposition: attachment; filename="'.$fileName.'"'); header("Content-Length: ".mb_strlen($text)); print($text); ob_end_flush(); exit();

Categories : Javascript
Download a zip file using Selenium WebDriver in Java - Download Popup is coming always
I think you are looking for something like this //common to all the cases FirefoxProfile prof = new FirefoxProfile(); //Case:1 - Use this case to set download this code to your browser's default location //prof.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/zip"); //Case:2 - Download file to Desktop //prof.setPreference("", 0); //prof.setPreferen

Categories : Java
How to add a download cancel button to download progress in android app
Use this example. public class Test extends Activity { public static final int DIALOG_DOWNLOAD_PROGRESS = 0; private Button startBtn; private ProgressDialog mProgressDialog; private final String KEY_TITLE = "Afromusics_file"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mProgressDialog.setCancelable(

Categories : Android
Media query is not working in my Iphone but is working in browser when i resize my browser
Try making it <meta name="viewport" content="width=device-width, initial-scale=1"> or <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> if you absolutely MUST disable zooming.

Categories : CSS
where can I download this code
As Lars says, your best bet is to look at the source code. To do this, you can use something like Chrome Developer Tools or Firebug for Firefox. I use the latter, so I'll take that as an example. First, I'd right-click on the visualization itself, and click on Inspect Element with Firebug. This will pull up the HTML, which is only semi-helpful, since it only shows the output rather than the JavaS

Categories : D3 Js
Recently Add
Rewrite of IDA decompiled function
Computing the average of grades in C
passing structures to functions
Use semaphores for handling sockets in C
How to search for a string pattern inside html, coding in C?
sprintf invalid format '%d'
Why can't this c program run correctly?
Low Pass filter in C
Child process does not print anything
C: datatypes. sqrt function working with int why?
How to implement Serial Port Profile Link Command used in ConnectBlue Bluetooth Module?
Rerunning cancelled pthread
How to print out a string that is pointed to by a char pointer?
Can unverified scanf call cause an undefined behavior?
nested structures in C
Portable Makevars for R package using C, GSL and OpenMP with help of Rcpp
program doesn't run(getting RUN FINISHED Segmentation fault core dumped)
Finding the sign of a Lua number, from C
Width of symbols created by gcc's objectcopy
Strange behavior when using free in c program
Can't open image C
Strange C code - dynamic arrays?
C program printing weird characters
Fault in decimal to binary in c
How to detect broken pipe on input?
How can I ivestigate use of the register keyword in C?
File scaning with fscanf
why gcc generates "leal -8240(%ebp), %eax; cmpl $1, %eax; ja XXX" instead of jmp instruction?
Wierd Problems With My Own Custom Written Word Search Algorithm
Trouble with making a shell in C
© Copyright 2017 Publishing Limited. All rights reserved.