InteractiveMind
asked on
Connect to PHP website, and pass params
I have a string, which I'd like to pass to a PHP webpage, in the form of either POST or GET data (whichever one is easiest).
e.g.
http://www.mydomain.com/myscript.php?getVar=mystr
Or whatever..
So that my PHP script can then parse the data, and store it on my web server.
Any ideas?
Thanks
e.g.
http://www.mydomain.com/myscript.php?getVar=mystr
Or whatever..
So that my PHP script can then parse the data, and store it on my web server.
Any ideas?
Thanks
I'd recommend using a library like libcurl for posting data: http://www.curl.haxx.se
--trigger-happy
--trigger-happy
ASKER
Any examples of use?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Right, I found a POST example:
#include <stdio.h>
#include <curl/curl.h>
int main(void)
{
CURL *curl;
CURLcode res;
char *postthis="moo mooo moo moo";
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://mydomain.com/page.php");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postthis);
/* if we don't provide POSTFIELDSIZE, libcurl will strlen() by
itself */
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(postthis));
res = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}
And I've copied the curl/.. lib into Dev-C++'s include folder, and have pointed my the directories within my Compiler Options to it, but am getting linker errors:
Compiler: Default compiler
Executing g++.exe...
g++.exe "C:\Documents and Settings\rob\Desktop\KL\po st.cpp" -o "C:\Documents and Settings\rob\Desktop\KL\po st.exe" -I"C:\Program Files\Dev-Cpp\include\c++\ 3.3.1" -I"C:\Program Files\Dev-Cpp\include\c++\ 3.3.1\ming w32" -I"C:\Program Files\Dev-Cpp\include\c++\ 3.3.1\back ward" -I"C:\Program Files\Dev-Cpp\lib\gcc-lib\ mingw32\3. 3.1\includ e" -I"C:\Program Files\Dev-Cpp\include" -I"C:\Program Files\Java\jdk1.5.0_01\inc lude" -I"C:\Program Files\Java\jdk1.5.0_01\inc lude\win32 " -I"C:\Program Files\Dev-Cpp\include\curl " -L"C:\Program Files\Dev-Cpp\lib" -L"C:\Program Files\Java\jdk1.5.0_01\inc lude" -L"C:\Program Files\Java\jdk1.5.0_01\inc lude\win32 " -L"C:\Documents and Settings\rob\Desktop\CpuUs age_src" -L"C:\masm32\lib" -L"C:\Program Files\Dev-Cpp\include\curl "
C:\DOCUME~1\rob\LOCALS~1\T emp/ccCWba aa.o(.text +0x54):pos t.cpp: undefined reference to `_imp__curl_easy_init'
C:\DOCUME~1\rob\LOCALS~1\T emp/ccCWba aa.o(.text +0x7a):pos t.cpp: undefined reference to `_imp__curl_easy_setopt'
C:\DOCUME~1\rob\LOCALS~1\T emp/ccCWba aa.o(.text +0x96):pos t.cpp: undefined reference to `_imp__curl_easy_setopt'
C:\DOCUME~1\rob\LOCALS~1\T emp/ccCWba aa.o(.text +0xba):pos t.cpp: undefined reference to `_imp__curl_easy_setopt'
C:\DOCUME~1\rob\LOCALS~1\T emp/ccCWba aa.o(.text +0xc7):pos t.cpp: undefined reference to `_imp__curl_easy_perform'
C:\DOCUME~1\rob\LOCALS~1\T emp/ccCWba aa.o(.text +0xd7):pos t.cpp: undefined reference to `_imp__curl_easy_cleanup'
Execution terminated
#include <stdio.h>
#include <curl/curl.h>
int main(void)
{
CURL *curl;
CURLcode res;
char *postthis="moo mooo moo moo";
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://mydomain.com/page.php");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postthis);
/* if we don't provide POSTFIELDSIZE, libcurl will strlen() by
itself */
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(postthis));
res = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}
And I've copied the curl/.. lib into Dev-C++'s include folder, and have pointed my the directories within my Compiler Options to it, but am getting linker errors:
Compiler: Default compiler
Executing g++.exe...
g++.exe "C:\Documents and Settings\rob\Desktop\KL\po
C:\DOCUME~1\rob\LOCALS~1\T
C:\DOCUME~1\rob\LOCALS~1\T
C:\DOCUME~1\rob\LOCALS~1\T
C:\DOCUME~1\rob\LOCALS~1\T
C:\DOCUME~1\rob\LOCALS~1\T
C:\DOCUME~1\rob\LOCALS~1\T
Execution terminated
ASKER
Hm, bloody hell. I didn't realise... everything within the 'Include' folder within the Libcurl download are mere header files!
ASKER
lol <btw, I meant that in a funny and sarcastic manner; not offensive>
I'm not sure what IDE you're using but you have to find a way to make it link to the curl library (you have to add "-lcurl" there).
--trigger-happy
--trigger-happy
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER