Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
HTTP Upload
C++ source code to upload one or more files (binary or text) to an HTTP server. void HttpUpload(void)
{
// C++ example to HTTP upload any file to an HTTP server.
CkHttp http;
// Unlock once at the beginning of your program.
http.UnlockComponent("Anything for 30-day trial");
// Create an HTTP request for file upload.
CkHttpRequest req;
req.UseUpload();
req.put_Path("/freeaspupload/testUpload.asp");
// The first argument to AddFileForUpload is an arbitrary name,
// the second argument is a filepath for a file that exists on your local
// filesystem.
req.AddFileForUpload("File1","dude.gif");
// This example will upload 2 files. To upload additional files,
// call AddFileForUpload once for each file to be uploaded.
req.AddFileForUpload("File2","dudeActiveX.gif");
// Upload the files by calling SynchronousRequest.
bool ssl = false; // Set this to true to use HTTPS
CkHttpResponse *resp = http.SynchronousRequest("www.freeaspupload.net",80,false,req);
if (!resp)
{
http.SaveLastError("httpError.xml");
}
else
{
if (resp->get_StatusCode() == 200)
{
// Everything is OK. Show the response information anyway...
CkString strStatusLine;
resp->get_StatusLine(strStatusLine);
printf("StatusLine = [%s]\n",strStatusLine.getString());
CkString strBody;
resp->get_BodyStr(strBody);
printf("--- HTTP Response Body ---\n%s\n",strBody.getString());
}
else
{
// Print the error...
CkString strStatusLine;
resp->get_StatusLine(strStatusLine);
printf("StatusLine = [%s]\n",strStatusLine.getString());
CkString strBody;
resp->get_BodyStr(strBody);
printf("--- HTTP Response Body ---\n%s\n",strBody.getString());
}
}
}
|
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2008 Chilkat Software, Inc. All Rights Reserved.