Пример #1
0
int main() 
{ 
    raw2();
    return 0; 
}
Пример #2
0
/** Submit the form filled with postedData
  *
  * \return \c true is success, otherwise \c false
  */
bool RainbruRPG::Network::Ident::CurlSubmitForm::submitForm(){
  bool ret=false;
  string s=postedData.getComputedData();

  handle=curl_easy_init();

  // Writing in a FILE structure using the built-in
  // cUrl write function (Only for submitted form's
  // not write to stdout)
  FILE* f;
  if ((f = fopen("curlget.xml", "w")) == NULL){
    LOGE(_("Error opening the FILE pointer"));
  }
  else{
    curl_easy_setopt(handle, CURLOPT_WRITEDATA, f);
  }

  // Curl URL setting
  LOGI(_("Setting the licurl URL"));
  std::string s2=filename;
  // Penser au 0 terminal	       
  int len2 = s2.length() + 1;
  std::vector<char> raw2(len2);
  const char* str2 = s2.c_str();
 
  std::copy(str2, str2 + len2, raw2.begin());

  curl_easy_setopt(handle, CURLOPT_URL, &(raw2[0]));

  // Using a vector to convert string to char*
  int len = s.length() + 1; // null terminators, rah rah rah
  std::vector<char> raw(len); // or is that "raw raw raw"?
  const char* str = s.c_str();

  // Do not use strcpy, memcpy etc.
  std::copy(str, str + len, raw.begin());
  //  brokenCFunction(&(raw[0])); 
  // Assuming the C function modifies the input string and we 
  // want to return the
  // modified version
  //  return std::string(&(raw[0]));
 


  // Ajoute le cookie de connexion
  curl_easy_setopt(handle, CURLOPT_COOKIE, "login=true;");



  //  curl_easy_setopt(handle, CURLOPT_URL, this->filename);
  //  char* data="name=essaiCurl4&pwd=curl&pwd2=curl&[email protected]";
  curl_easy_setopt(handle, CURLOPT_POSTFIELDS,&(raw[0]) );
  curl_easy_setopt(handle, CURLOPT_POST, 1);
  CURLcode success=curl_easy_perform(handle); /* post away! */

  if (success==0){
    LOGI(_("The form was successfully submited"));
    ret=true;
  }
  else{
    LOGW(_("An error occured during submitForm"));
  }


  // Get the last response code
  CURLcode a=curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, 
			       &serverResponse);

  if (serverResponse>199 & serverResponse<300)
    ret=true;
  else 
    ret=false;

  if (a==0){
    LOGI(_("Setting server response successfull"));
  }
  else{
    LOGW(_("Cannot get the server response"));
  }

  curl_easy_cleanup( handle );
  fclose(f);

  return ret;
}