Hi Daniel,
   You can find the actual file,which i was trying,with the attachment.Is
there anything wrong iam doing??


Thanks
Sumana


On 8/18/09, sumana ts <[email protected]> wrote:
>
> Hi Daniel,
>    I was trying  http://curl.haxx.se/lxr/source/docs/examples/postit2.c.
> Something very similar to it.
>
> Thanks
> Sumana
>
>
>  On 8/18/09, Daniel Stenberg <[email protected]> wrote:
>>
>> On Tue, 18 Aug 2009, sumana ts wrote:
>>
>>  I have downloaded 7.19.5 source and compiled for linux OS.I have written
>>> a
>>> simple client which does a URL form post.
>>>
>>> But it is not working for me.:(.Problem is conn->data->set is getting
>>> corrupted/modified as soon as it invokes Curl_connecthost function.
>>>
>>
>> You mean like:
>>
>>        http://curl.haxx.se/lxr/source/docs/examples/http-post.c
>>
>> Tried using valgrind to get some further clues?
>>
>> --
>>
>>  / daniel.haxx.se
>>
>
>
/*****************************************************************************
 *                                  _   _ ____  _
 *  Project                     ___| | | |  _ \| |
 *                             / __| | | | |_) | |
 *                            | (__| |_| |  _ <| |___
 *                             \___|\___/|_| \_\_____|
 *
 * $Id: postit2.c,v 1.5 2007-07-12 21:11:10 danf Exp $
 *
 * Example code that uploads a file name 'foo' to a remote script that accepts
 * "HTML form based" (as described in RFC1738) uploads using HTTP POST.
 *
 * The imaginary form we'll fill in looks like:
 *
 * <form method="post" enctype="multipart/form-data" action="examplepost.cgi">
 * Enter file: <input type="file" name="sendfile" size="40">
 * Enter file name: <input type="text" name="filename" size="30">
 * <input type="submit" value="send" name="submit">
 * </form>
 *
 * This exact source code has not been verified to work.
 */

#include <stdio.h>
#include <string>
using namespace std;

#include <../../include/curl/curl.h>
#include <../../include/curl/types.h>
#include <../../include/curl/easy.h>

int main(int argc, char *argv[])
{
  CURL *curl;
  CURLcode res;

  struct curl_httppost *formpost=NULL;
  struct curl_httppost *lastptr=NULL;
  struct curl_slist *headerlist=NULL;
  static const char buf[] = "Expect:";
  char fileName[50]= "DS000004001.jpg";
  string httpUrl = "http://16.181.215.213/httpdestination.aspx";;

  curl_global_init(CURL_GLOBAL_ALL);

  /* Fill in the file upload field */
  for(int i=0; i<2; i ++)
  {
   curl_formadd(&formpost,
               &lastptr,
               CURLFORM_COPYNAME, "sendfile",
               CURLFORM_FILE, fileName,
               CURLFORM_CONTENTTYPE, "image/jpeg",
               CURLFORM_END);
  }

  curl = curl_easy_init();
  /* initalize custom header list (stating that Expect: 100-continue is not
     wanted */
  headerlist = curl_slist_append(headerlist, buf);
  headerlist = curl_slist_append(headerlist, "Accept: */*");
  headerlist = curl_slist_append(headerlist, "Connection: Keep-Alive");
  headerlist = curl_slist_append(headerlist, "User-Agent: Mozilla/4.0");
  headerlist = curl_slist_append(headerlist, "Accept-Language: en-us");
  headerlist = curl_slist_append(headerlist, "Accept-Encoding: gzip, deflate");
  headerlist = curl_slist_append(headerlist, "Host: 16.181.215.213");

  if(curl) {
    /* what URL that receives this POST */
    curl_easy_setopt(curl, CURLOPT_URL, httpUrl.c_str());
    //curl_easy_setopt(curl, CURLOPT_URL, 
"http://16.181.215.213/httpdestination.aspx";);
    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
    curl_easy_setopt(curl, CURLOPT_PROXY, "");
    curl_easy_setopt(curl, CURLOPT_TIMEOUT, 30L);
    curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10L);
    /*if ( (argc == 2) && (!strcmp(argv[1], "noexpectheader")) )*/
      /* only disable 100-continue header if explicitly requested */
      curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
    curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
    res = curl_easy_perform(curl);
    printf("res is :%d\n",res);

    /* always cleanup */
    curl_easy_cleanup(curl);

    /* then cleanup the formpost chain */
    curl_formfree(formpost);
    /* free slist */
    curl_slist_free_all (headerlist);
  }
  return 0;
}

Reply via email to