PDA

View Full Version : Talking to php using WinInet


cliffski
05-27-2006, 02:09 PM
Ok I'm a little stuck here. I have a php page that takes in some variables and writes them to disk. so I kinda have this:

www.positech.co.uk/test.php?var1=zog

which if I stick into firefox, it does what it says on the tin, and My value "zog" gets written in a file.
If I use WinInet to request the same URL, sod all happens. I'm checking my return codes from all my functions, everything checks out ok, but nothing happens at the server side.

I've tried using POST instead of GET in the httpOpenRequest stuff. Im not mucking around with additional headers because as I understand it, I just need to call SendRequest() on that url and it should run the php and do the right thang?

I've spent ages googling but cant find anyone using wininet to talk to php using url variables. can it be done?
I looked at happyhttp but it wouldnt link on my setup ;(

if its easier, forget php, how can i append data to a file at the server using wininet? my feeble attempts at using InternetWriteFile() also amount to nothing. is php the thing to use here? or even CGI?
I am teh n00b.

TheMysteriousStranger
05-27-2006, 02:18 PM
If you're looking for a straight url open, look up the function InternetOpenURL in wininet. It encapsulates a lot of the send request stuff and simplifies matters a lot. I have a system set up using InternetOpenURL, sending variables to php, and it works perfectly.

Also, are you reading the contents of the file using wininet? It's possible that simply opening the url is not enough and if you don't download the php output from the server, it may not be completing the script on the server end. Take a look here:

Linky (http://www.dotnetheaven.com/Uploadfile/mahesh/commonWinInetAPI05242005064319AM/commonWinInetAPI.aspx?ArticleID=6335300f-3eda-4199-9888-a71fc138fb73)

It's the tutorial I used to get wininet up and running. It covers the basics and from there doing anything more complex should be pretty simple.

cliffski
05-27-2006, 02:51 PM
aha yes, that does indeed do it. cheers!

TheMysteriousStranger
05-27-2006, 03:07 PM
So was it using InternetOpenURL that worked or was it because you weren't reading the download buffer? (I'd like to know, because I'm anal like that :D )

cliffski
05-27-2006, 03:23 PM
using InternetOpenURL sorted it fine :D

oNyx
05-27-2006, 04:23 PM
For debugging this kind of thing a sniffer (http://www.ethereal.com/) is pretty handy.

Saved me from lots of hairpulling and guessing.