posting data with wxHTTP Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
FireMail
Earned some good credits
Earned some good credits
Posts: 122
Joined: Fri Jun 10, 2005 8:34 am
Location: Austria
Contact:

posting data with wxHTTP

Post by FireMail »

hi there,

wxHTTP is relatively uncommented in the docs. is there a way to post data to a php script easily?

kind regards juergen
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GB/CS/CM/IT !d++ s+:-- a-- C++++$ UBL*++++$ P--- L++++$ !E-- !W+++$? !N-- !o K--? w++()$ !O M$ !V !PS? !PE? !Y? !PGP !t !5 !X R+++ tv++ !b? DI D++ G e+++ h++ r++ y+
------END GEEK CODE BLOCK------
mc2r
wxWorld Domination!
wxWorld Domination!
Posts: 1195
Joined: Thu Feb 22, 2007 4:47 pm
Location: Denver, Co
Contact:

Re: posting data with wxHTTP

Post by mc2r »

FireMail wrote:wxHTTP is relatively uncommented in the docs. is there a way to post data to a php script easily?
Yes, but not with wxHTTP. CURL is very useful, full featured, easy and works well with wxWidgets. There is also a wx wrapper called wxCurl, but i can't testify to it's usefulness as i just use CURL directly.

-Max
FireMail
Earned some good credits
Earned some good credits
Posts: 122
Joined: Fri Jun 10, 2005 8:34 am
Location: Austria
Contact:

Post by FireMail »

is curl platform independent?
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GB/CS/CM/IT !d++ s+:-- a-- C++++$ UBL*++++$ P--- L++++$ !E-- !W+++$? !N-- !o K--? w++()$ !O M$ !V !PS? !PE? !Y? !PGP !t !5 !X R+++ tv++ !b? DI D++ G e+++ h++ r++ y+
------END GEEK CODE BLOCK------
mc2r
wxWorld Domination!
wxWorld Domination!
Posts: 1195
Joined: Thu Feb 22, 2007 4:47 pm
Location: Denver, Co
Contact:

Post by mc2r »

FireMail wrote:is curl platform independent?
Yes, I'm not sure every platform it builds on but I've used it fine on linux and msw.

-Max
Ryan Wilcox
I live to help wx-kind
I live to help wx-kind
Posts: 194
Joined: Mon Aug 30, 2004 1:26 pm
Location: PA, USA
Contact:

Post by Ryan Wilcox »

I have a wxHTTPPost class

https://anon:@scm.wilcoxd.com:8081/svn/ ... xHTTPPost/

Also, wxCurl is pretty good - and easier than using curl directly (as I've done both approaches)

Hope this helps
Ryan Wilcox
Wilcox Development Solutions
http://www.wilcoxd.com
FireMail
Earned some good credits
Earned some good credits
Posts: 122
Joined: Fri Jun 10, 2005 8:34 am
Location: Austria
Contact:

Post by FireMail »

i tried it now with curl directly - its really easy to use, but it looks for me like i made an error. maybe you find quickly whats wrong here.

i try to upload an image with curl - by using a php file.

curl code:

Code: Select all

	CURL *easyhandle = curl_easy_init(); 
	curl_easy_setopt( easyhandle, CURLOPT_URL, "http://url.com/upload.php" );
char *error = new char[CURL_ERROR_SIZE];
curl_easy_setopt(easyhandle, CURLOPT_ERRORBUFFER, error);

	curl_httppost *post = NULL;
	curl_httppost *last = NULL;
	curl_slist *headers = NULL;
	
	headers = curl_slist_append( headers, "Content-Type: image/png");

	curl_formadd( &post, &last, CURLFORM_COPYNAME, "user", CURLFORM_COPYCONTENTS, "990", CURLFORM_END );
	curl_formadd( &post, &last, CURLFORM_COPYNAME, "pic", CURLFORM_FILECONTENT, "unknown.png", CURLFORM_CONTENTHEADER, headers, CURLFORM_END);

	curl_easy_setopt( easyhandle, CURLOPT_HTTPPOST, post );
	curl_easy_perform( easyhandle );

	curl_formfree( post ); 
	curl_slist_free_all( headers );
the php code:

Code: Select all

$fp = fopen( $_POST['user'].".png", "wb+" );
fwrite( $fp, $_POST['avatare'] );
fclose($fp);
data is uploaded and everything works fine, except that the uploaded data is not the same as the original one - the image gets corrupted. maybe you have an idea. kind regards
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GB/CS/CM/IT !d++ s+:-- a-- C++++$ UBL*++++$ P--- L++++$ !E-- !W+++$? !N-- !o K--? w++()$ !O M$ !V !PS? !PE? !Y? !PGP !t !5 !X R+++ tv++ !b? DI D++ G e+++ h++ r++ y+
------END GEEK CODE BLOCK------
Post Reply