(Convert VB.Net to C++) Send Form Post Variables from C++ to HTTP

Joined
Dec 10, 2006
Messages
540
I'm trying to convert a Windows VB.Net GUI application to a C++ command line program and I'm having some issues converting a certain section of code. I know very little C++ so it's difficult.

Here is the VB.Net code:
Code:
       Dim web As New System.Net.WebClient
        web.Headers.Add("User-Agent", " Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.13) Gecko/2009073022 Firefox/3.0.13 (.NET CLR 3.5.30729)")
        web.Headers.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
        web.Headers.Add("Accept-Language", "en-us,en;q=0.5")
        web.Headers.Add("Accept-Encoding", "gzip,deflate")
        web.Headers.Add("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7")
        web.Headers.Add("Keep-Alive", "300")
        web.Headers.Add("Referer", "https://example.com/")
        web.Headers.Add("Cookie", "PHPSESSID=")
        web.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
        Dim d As Byte() = System.Text.Encoding.ASCII.GetBytes("Var1=test&Var2=test")
        Dim res As Byte() = web.UploadData("https://example.com", "POST", d)
        Return System.Text.Encoding.ASCII.GetString(res)

I would love any help. Thanks guys.
 
Stock C++ doesn't have any HTTP libraries. You'll have to find a 3rd-party one and link to that (unless you want to write your own, which you probably don't).
 
how do you plan on using this c++ cmd line app? for cgi or something?

you'd need to track down a library to handle the headers, but thats going to depend on how you plan on running it.
 
can't you make a command line application with vb/.net? i mean, you can with c#. forgive me if that's just naive or perhaps there's a reason it needs to be c++ you haven't mentioned.
 
The app needs to be in C++ because it must run on Windows/Mac OS X/Linux. So since VB.Net does have the ability to be a command line app, the .NET framework is not cross platform, so its a no go. The application will just run from the command line and do some calculations and then finally send two variables with some headers to a certain website. Does anybody have any suggestions for a library that I could use?
 
things written in C++ aren't necessarily cross platform either, not by any stretch.

You'd actually have a working program faster writing it in .NET then running it under mono on OSX and linux, if you are already familiar with .NET.

The app needs to be in C++ because it must run on Windows/Mac OS X/Linux. So since VB.Net does have the ability to be a command line app, the .NET framework is not cross platform, so its a no go. The application will just run from the command line and do some calculations and then finally send two variables with some headers to a certain website. Does anybody have any suggestions for a library that I could use?
 
have you thought about using python or java? both are cross platform, and both have http client libraries available, which is what you want to be using to set the headers.

python has the added benefit of having an interactive interpreter available, so you can try things out as you type them.

You will need the java runtime (JRE) or python installed for such an app to work though.

for c++ you need to find a http client library, but you might not find a library that works on all the platforms you listed, so you will wind up developing separate apps per OS anyway.
 
I finally did some more work on this and I think my final plan is to just use C# and Mono. So far my trials have been successful. Now I just have to make it look pretty.
 
Back
Top