How to post some text to my webserver (PHP)

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
eriX
Experienced Solver
Experienced Solver
Posts: 84
Joined: Wed Feb 04, 2009 2:08 pm
Location: Germany
Contact:

How to post some text to my webserver (PHP)

Post by eriX »

Hello everybody.

You all know the input-forms on every website where you can put text in and submit it.
I want to post some data as a string to my 'upload.php' file on my webserver.
Then I want to work with this submitted data and generate a response that goes back to the programme.

Could you give me some hints, please, how I can easily post some text to this php file.
I want to catch it on my server simply with $mytext = $POST['mystring'];

If you want to suggest me cURL, then please give me a description how I implement and link it...
I spent much time at this and didn't get it to compile.

Thank you very much!
- Eric
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to post some text to my webserver (PHP)

Post by doublemax »

If you just want to pass a few text variables, just add them to the url, like you would when you type the url into a browser:

Code: Select all

wxHTTP http;
http.Connect(wxT("www.someserver.nix"), 80);
wxInputStream *httpStream=http.GetInputStream(wxT("/test.php?var1=hallo&var2=wxwidgets"));
if(httpStream!=NULL) {
  wxString res;
  wxStringOutputStream out_stream(&res);
  httpStream->Read(out_stream);
  wxLogMessage(res);
  delete httpStream;
}
Use the source, Luke!
eriX
Experienced Solver
Experienced Solver
Posts: 84
Joined: Wed Feb 04, 2009 2:08 pm
Location: Germany
Contact:

Re: How to post some text to my webserver (PHP)

Post by eriX »

I discovered this way already.
But I have to post unicode-text with a lot of chars that don't match the URL-chars...
So I think I have to perform a real POST to get it, but I don't know how to do it.
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to post some text to my webserver (PHP)

Post by doublemax »

That would still work if you url-encode the parameters. I don't think there is any wxWidgets method for that, but it should be trivial enough to code it yourself.

You could also check out wxHTTPEngine:
http://wxcode.sourceforge.net/components/httpengine/
(class wxHTTPBuilder would be what you're looking for)
Use the source, Luke!
eriX
Experienced Solver
Experienced Solver
Posts: 84
Joined: Wed Feb 04, 2009 2:08 pm
Location: Germany
Contact:

Re: How to post some text to my webserver (PHP)

Post by eriX »

I would prefer a real post, not via URL.

Can I add some headers to wxHTTP?
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to post some text to my webserver (PHP)

Post by doublemax »

http://docs.wxwidgets.org/stable/wx_wxh ... psetheader

There is also void wxHTTP::SetPostBuffer(const wxString& post_buf)
It's not documented in 2.8.x, but it exists. But you have to build the content of the buffer yourself.
Use the source, Luke!
eriX
Experienced Solver
Experienced Solver
Posts: 84
Joined: Wed Feb 04, 2009 2:08 pm
Location: Germany
Contact:

Re: How to post some text to my webserver (PHP)

Post by eriX »

I played a little bit with the cURL.exe command-line-tool. I'm satisfied :D
I'd like to use cURL in my project.

Can you help me at implementing it, please?
I've got no idea which files I shall copy in which directory...
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to post some text to my webserver (PHP)

Post by doublemax »

Can you help me at implementing it, please?
I've got no idea which files I shall copy in which directory...
That very much depends on the compiler/ide you're using. With Visual Studio you just add the libcurl library to your linker input files and add the libcurl include path to the compiler input directories and that's it.

I don't know about other IDEs or platforms, but i guess it should be similar.
Use the source, Luke!
User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2409
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania

Re: How to post some text to my webserver (PHP)

Post by evstevemd »

eriX wrote:I'd like to use cURL in my project.
check wxCurl
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
Post Reply