cURL
Haxx ad
libcurl

curl's project page on SourceForge.net

Sponsors:
Haxx

cURL > Mailing List > Monthly Index > Single Mail

curlpp mailing list Archives

[cURLpp] Newbie help connecting to ssl

From: John Vorwald <john_vorwald_at_msn.com>
Date: Wed, 27 Sep 2006 05:54:00 -0400

The code below is an attempt to login into the site
https://tspweb2.tspsec.tsp.gov/. As written, the code does not return
anything.

#include <cstdlib>
#include <fstream>
#include <iostream>

#include <string>
#include <curl/curl.h>

std::ofstream os_log;

// Buffer for holding web access errors
static char errorBuffer[CURL_ERROR_SIZE];

// This is the writer call back function used by curl
static int web_writer(char *data, size_t size, size_t nmemb,
                  std::string *buffer)
{
  // What we will return
  int result = 0;

  // Is there anything in the buffer?
  if (buffer != NULL)
  {
    // Append the data to the buffer
    buffer->append(data, size * nmemb);

    // How much did we write?
    result = size * nmemb;
  }

  return result;
}

int main(int argc, char *argv[])
{

  std::string url("http://www.tsp.gov/account/index.html#login"),
                  tsp_user_id("SSN"),
                 tsp_user_password("PASS");

  // url = "https://tspweb2.tspsec.tsp.gov/";

  os_log.open("output.log",std::fstream::out);

  // Write all expected data in here
  static std::string web_buffer;

  // Our curl objects
  CURL *curl;
  CURLcode result;

  bool is_done(false), is_first_call(true);

  while (!is_done)
  {
    // Create our curl handle
    curl = curl_easy_init();

    if (curl)
    {
      // Now set up all of the curl options
      curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorBuffer);
      curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
      curl_easy_setopt(curl, CURLOPT_HEADER, 0);
     // curl_easy_setopt(curl, CURLOPT_RETURNTRANSFER, 1);
      curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);

      curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, web_writer);
      curl_easy_setopt(curl, CURLOPT_WRITEDATA, &web_buffer);

      curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U;
Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)");
      curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2);
      curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);

      // Attempt to retrieve the remote page
      web_buffer.erase(0, web_buffer.length());
      result = curl_easy_perform(curl);

      // Always cleanup
      curl_easy_cleanup(curl);

      os_log << web_buffer;

    } // if curl
    else
    {
      // Always cleanup
      std::cout << "Unable to initalize curl" << std::endl;
      curl_easy_cleanup(curl);
      is_done = true;
    }
    is_done = true;
  }
  os_log.close();
  // system("PAUSE");
  return EXIT_SUCCESS;
}

_______________________________________________
cURLpp mailing list
cURLpp_at_rrette.com
http://www.rrette.com/mailman/listinfo/curlpp
Received on 2006-09-27

These mail archives are generated by hypermail.

donate! Page updated November 12, 2010.
web site info

File upload with ASP.NET