curl-library
In what order the information will be sent?
Date: Wed, 25 Jul 2012 21:59:11 -0700
Hi, ALL,
I'm trying to port some VB code to libCURL.
The order in which VB program sends data is:
1. Set content-type to be "multipart/form-data;
boundary=---------------------------" + timestamp
2. Write "\n\r-----------------------------" + timestamp + "\n\r"
3. Write "Content-Disposition: form-data; name="MyFile";
filename="12345.bmp"\r\nContent-Type: image/bitmap\r\n\r\n"
4. POST'ing the content of the "12345.bmp"
Here is the ASP/HTML for this code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<div>
<form id="Form2" Method="Post" EncType="Multipart/Form-Data" RunAt="Server">
<%-- The File upload Html control --%>
Choose Your File To Upload <BR>
<Input Name="MyFile" id="MyFile" Type="File" RunAt="Server">
<BR>
<%-- A button - when clicked the form is submitted and the
Upload_Click event handler is fired... --%>
<Input id="Submit1" Type="Submit" Value="Upload"
RunAt="Server">
</form> </div>
</body>
</html>
And that's how I translated the code for libCURL:
wxString header = wxString::Format( "Content-Disposition: form-data;
name=\"MyFile\"; filename=\"%s\"", fileName );
post = curl_slist_append( post, "Content-Type: multipart/form-data;
boundary=---------------------------12345" );
post = curl_slist_append( post, header.c_str() );
if( !post )
{
return;
}
post = curl_slist_append( post, "Content-Type: image/bitmap" );
if( !post )
{
curl_slist_free_all( post );
return;
}
result = curl_formadd( &first, &last, CURLFORM_COPYNAME, "name",
CURLFORM_FILE, (const char *) fileName.c_str(), CURLFORM_END );
result = curl_formadd( &first, &last, CURLFORM_COPYNAME, "filename",
CURLFORM_COPYCONTENTS, (const char *) fileName.c_str(),
CURLFORM_CONTENTHEADER, post, CURLFORM_END );
result = curl_formadd(&first, &last, CURLFORM_COPYNAME, "submit",
CURLFORM_COPYCONTENTS, "send", CURLFORM_END );
if( result )
{
curl_slist_free_all( post );
curl_formfree( first );
return;
}
CURL *handle = wxGetApp().GetCurlHandle();
FILE *fp = fopen( "session.log", "w+" );
if( !fp )
{
curl_slist_free_all( post );
curl_formfree( first );
return;
}
curl_easy_setopt( handle, CURLOPT_VERBOSE, 1L );
curl_easy_setopt( handle, CURLOPT_HEADER, 1L );
curl_easy_setopt( handle, CURLOPT_STDERR, fp );
curl_easy_setopt( handle, CURLOPT_ERRORBUFFER, errorMsg );
curl_easy_setopt( handle, CURLOPT_URL, "http://xxx.xxx.xxx.xxx/Default.aspx" );
curl_easy_setopt( handle, CURLOPT_HTTPPOST, first );
error = curl_easy_perform( handle );
if( !error )
{
curl_slist_free_all( post );
curl_formfree( first );
return;
}
curl_slist_free_all( post );
curl_formfree( first );
curl_easy_setopt( handle, CURLOPT_HTTPPOST, NULL );
curl_easy_setopt( handle, CURLOPT_HTTPHEADER, NULL );
Is this correct translation?
Thank you.
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2012-07-26