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] send a post, get request to a HTTPs server

From: <Surfman19_at_gmx.at>
Date: Sat, 9 Jul 2005 01:25:57 +0200 (MEST)

hi!
i want can i user curl lib to send a GET, POST request to a HTTPS server?
can you help me a little bit...i dont know how to get the requestBody...
see the code down...

-----------------------
that i want to do:
-----------------------

browse to the site to get the JSESSIONID
----------------------------------------
GET /webkeeper/Controller HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/x-shockwave-flash, application/vnd.ms-excel,
application/vnd.ms-powerpoint, application/msword,
application/x-gsarcade-launch, */*
Accept-Language: de-at
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR
1.1.4322)
Host: www.myzone.at
Connection: Keep-Alive

reques from server:
-----------------------
HTTP/1.0 200 OK
Date: Tue, 21 Jun 2005 18:17:50 GMT
Server: Apache/2.0.52 (Unix) mod_ssl/2.0.52 OpenSSL/0.9.7d mod_jk2/2.0.4
Set-Cookie: JSESSIONID=57624CE7672877DC0A8930591F678F01; Path=/webkeeper;
Secure
Content-Type: text/html; charset=ISO-8859-1
Connection: close

login
---------------------------------
POST /webkeeper/Controller HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/x-shockwave-flash, application/vnd.ms-excel,
application/vnd.ms-powerpoint, application/msword,
application/x-gsarcade-launch, */*
Referer: https://www.myzone.at/webkeeper/Controller
Accept-Language: de-at
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR
1.1.4322)
Host: www.myzone.at
Content-Length: 86
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: JSESSIONID=57624CE7672877DC0A8930591F678F01

action=login&login=Anmelden&brand=myzone&username=user&password=passwdb&x=35&y=18

send a sms:
-------------------------
POST /webkeeper/Controller HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/x-shockwave-flash, application/vnd.ms-excel,
application/vnd.ms-powerpoint, application/msword,
application/x-gsarcade-launch, */*
Referer: https://www.myzone.at/webkeeper/Controller?action=sms
Accept-Language: de-at
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR
1.1.4322)
Host: www.myzone.at
Content-Length: 72
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: JSESSIONID=57624CE7672877DC0A8930591F678F01

psid=0&smsnetz=004412331&handynr=111111&nachr=test&num=131&action=sendsms

request from server:
-----------------------
HTTP/1.0 200 OK
Date: Tue, 21 Jun 2005 18:19:51 GMT
Server: Apache/2.0.52 (Unix) mod_ssl/2.0.52 OpenSSL/0.9.7d mod_jk2/2.0.4
Content-Type: text/html; charset=ISO-8859-1
Connection: close

i tried it in c++, but how can i get the requestBody??? is my concept ok?
--------------------------------------------------------------
#include <iostream>
#include <string>
#include <curl/curl.h>
using namespace std;

#pragma comment(lib,"libcurl.lib")

int main()
{
 string serverAddress="https://212.152.190.183/webkeeper/Controller";
 CURL *curl;
    CURLcode res;
     
    curl_global_init(CURL_GLOBAL_ALL);
    curl = curl_easy_init();
     
    if ( curl ){
      struct MemoryStruct chunk;

 curl_easy_setopt(curl, CURLOPT_URL, serverAddress_.c_str() );
       
      /* send all data to this function */
      curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
       
      /* we pass our 'chunk' struct to the callback function */
      curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
       
       
      if( requestBody.size() > 0 ){
        response_="";
         
        curl_easy_setopt( curl, CURLOPT_POST, 1);

        curl_easy_setopt( curl, CURLOPT_POSTFIELDSIZE, requestBody.size() );

        curl_easy_setopt( curl, CURLOPT_POSTFIELDS, requestBody.c_str() ) ;

 /* some servers don't like requests that are made without a user-agent
        field, so we provide one */
        curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-agent/1.0");
         

        //trick to make ssl connection without installing the server's CA
certificate:
        //set disabel SSL_VERIFYPEER and enable SSL_VERIFYHOST. Necessary
for libcurl > 7.10
         
        curl_easy_setopt( curl, CURLOPT_SSL_VERIFYPEER, 0);
        curl_easy_setopt( curl, CURLOPT_SSL_VERIFYHOST, 1);

 if( !httpUsername_.empty() ){
         
        std::string userpwd = httpUsername_ + ":" + httpPassword_;
        curl_easy_setopt( curl, CURLOPT_USERPWD, userpwd.c_str());
         
         
        if ( NoCaseEqual( httpAuthenticationMethod_, "any") )
curl_easy_setopt(curl, CURLOPT_HTTPAUTH,CURLAUTH_ANY);
        else if ( NoCaseEqual( httpAuthenticationMethod_, "basic") )
curl_easy_setopt(curl, CURLOPT_HTTPAUTH,CURLAUTH_BASIC);
        else if ( NoCaseEqual( httpAuthenticationMethod_, "digest") )
curl_easy_setopt(curl, CURLOPT_HTTPAUTH,CURLAUTH_DIGEST);
        else if ( NoCaseEqual( httpAuthenticationMethod_, "ntlm") )
curl_easy_setopt(curl, CURLOPT_HTTPAUTH,CURLAUTH_NTLM );
        else {
          curl_easy_setopt(curl, CURLOPT_HTTPAUTH,CURLAUTH_ANY);
        }
         
      }
       
      if ( cookie_.size() > 0) {
        curl_easy_setopt(curl, CURLOPT_COOKIE, cookie_);
      }
       
       
      response_="";
      res = curl_easy_perform(curl);
      if ( res == 0 ) {
        result = true;
        response_ = chunk.memory;
      }
       
      curl_easy_cleanup(curl);

  cin.get();
  return 0;
}

-- 
Weitersagen: GMX DSL-Flatrates mit Tempo-Garantie!
Ab 4,99 Euro/Monat: http://www.gmx.net/de/go/dsl
_______________________________________________
cURLpp mailing list
cURLpp_at_rrette.com
http://www.rrette.com/mailman/listinfo/curlpp
Received on 2005-07-09

These mail archives are generated by hypermail.

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

File upload with ASP.NET