Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ MT-multithreading and servers » fileupload and post data
fileupload and post data [message #59967] Tue, 27 June 2023 22:37 Go to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
Hello,

here is a code able to perform a file upload (I have added #include <Core/SSL/SSL.h> )

void fileupload::upload()
{
    String url = "https://validurl/transfer.php";
    httprequest r(url);
    String fn = "C:/upp/out/MyApps/MSBT17.Gui/test.pdf";
    String s = LoadFile(fn); 
    r.POST();
    r.Part("file", s , "multipart/form-data", fn);
    r.Execute();   
}


Now I want not only upload a file but even post some data. Here is the new version

void fileupload::upload()
{
    String url = "https://validurl/transfer.php";
    httprequest r(url);
    String fn = "C:/upp/out/MyApps/MSBT17.Gui/test.pdf";
    String s = LoadFile(fn); 
    r.POST();
    r.Part("file", s , "multipart/form-data", fn);
	
    r.Post("username", USER);
    r.Post("password", PASS);
  
    r.Execute();   
}


Unfotunately it does not work for some reason. Perhaps I am misusing Part() and Post(). Which is the correct way to make a httprequest with file and post data?

Thanks,
Luigi
Re: fileupload and post data [message #59972 is a reply to message #59967] Thu, 29 June 2023 10:34 Go to previous message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
After several tests this seems to work

void fileupload::upload()
{
    String url = "https://validurl/transfer.php";
    httprequest r(url);
    String fn = "C:/upp/out/MyApps/MSBT17.Gui/test.pdf";
    String s = LoadFile(fn); 
    r.POST();
    r.Part("file", s , "multipart/form-data", fn);

    r.Part("username", FTPUSER , "multipart/form-data");
    r.Part("password", FTPPASS , "multipart/form-data");
  
    r.Execute();   
}


Luigi

[Updated on: Thu, 29 June 2023 10:35]

Report message to a moderator

Previous Topic: error / memory leak in HttpServer example
Next Topic: HttpRequest - desktop client U++ (accessing java tomcat server)
Goto Forum:
  


Current Time: Wed May 15 17:30:48 CEST 2024

Total time taken to generate the page: 0.02860 seconds