cURL / Mailing Lists / curl-library / Single Mail

curl-library

how to use libcurl to post

From: xiao niu <xiaoniu732000_at_yahoo.com.cn>
Date: Sat, 14 Jun 2003 17:51:19 +0800 (CST)

Hi, all
 
I want to write a program to upload something using HTTP POST, but failed.
 
here is the source code of html file:
 
<form action=/ProdSearch/prodsearch.asp?uid=suuszxsswugibgzsmsgsasxww id=form2 method=post name=form2>
<input id=vname onMouseOver=javascript:this.focus()
 style="BORDER-RIGHT: #cc6600 1px solid; BORDER-TOP: #cc6600 1px solid; FONT-SIZE: 12px; BORDER-LEFT: #cc6600 1px solid; WIDTH: 75px; BORDER-BOTTOM: #cc6600 1px solid; BACKGROUND-COLOR: #ffffff"
 onFocus=javascript:this.select() size=10 value=all
 name=vname>
<select
 id=kind style="FONT-SIZE: 12px" name=kind>
 <option value="" selected>all kinds</option>
 <option value=bk>book</option>
 <option value=ys>VCD</option>
 <option value=mu>music</option>
 <option value=gm>game</option>
 <option value=rj>software</option>
 <option value=zm>store</option>
</select>
<input type=image alt=search
  src="http://images.joyo.com/s/search_sousuo1.gif" border=0 name="image2" width="45" height="21">
<a href="/ProdSearch/advsearch.asp?uid=suuszxsswugibgzsmsgsasxww"><img src="http://images.joyo.com/s/sousuo_z020614_01.gif" width="59" height="21" border="0" alt="precise search"></a></td>
 

and here is my code:
 
  /* Fill in the vname field */
  curl_formadd(&formpost,
               &lastptr,
               CURLFORM_COPYNAME, "vname",
               CURLFORM_COPYCONTENTS, "linux",
               CURLFORM_END);
  /* Fill in the kind field */
  curl_formadd(&formpost,
               &lastptr,
               CURLFORM_COPYNAME, "kind",
               CURLFORM_COPYCONTENTS, "",
               CURLFORM_END);
  curl = curl_easy_init();
  /* initalize custom header list (stating that Expect: 100-continue is not
     wanted */
  headerlist = curl_slist_append(headerlist, buf);
  if(curl) {
    /* what URL that receives this POST */
    curl_easy_setopt(curl, CURLOPT_URL, "http://www.joyo.com.cn/ProdSearch/prodsearch.asp?uid=suuszxsswugibgzsmsgsasxww");
    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);
    /* always cleanup */
    curl_easy_cleanup(curl);
    /* then cleanup the formpost chain */
    curl_formfree(formpost);
    /* free slist */
    curl_slist_free_all (headerlist);
  }
 
 
here is the result:
<head><title>Object moved</title></head>
<body><h1>Object Moved</h1>This object may be found here.</body>
 
 
what will cause that error? did i use the libcurl correctly? or maybe the server do not allow such request?
thanks in advance for any help.
xiaoniu

---------------------------------
Do You Yahoo!?
"流连网络世界的“你”是谁?

-------------------------------------------------------
This SF.NET email is sponsored by: eBay
Great deals on office technology -- on eBay now! Click here:
http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5
Received on 2003-06-14