Page 1 of 1

How to post some text to my webserver (PHP)

Posted: Sun Aug 05, 2012 7:24 pm
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

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

Posted: Sun Aug 05, 2012 7:57 pm
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;
}

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

Posted: Sun Aug 05, 2012 8:03 pm
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.

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

Posted: Sun Aug 05, 2012 9:22 pm
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)

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

Posted: Mon Aug 06, 2012 5:51 pm
by eriX
I would prefer a real post, not via URL.

Can I add some headers to wxHTTP?

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

Posted: Mon Aug 06, 2012 6:08 pm
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.

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

Posted: Wed Aug 15, 2012 1:48 pm
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...

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

Posted: Wed Aug 15, 2012 3:47 pm
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.

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

Posted: Wed Aug 15, 2012 4:15 pm
by evstevemd
eriX wrote:I'd like to use cURL in my project.
check wxCurl