ارسال پارامتر به یک صفحه PHP با زبان برنامه نوسی C++
با سلام
من می خوام که با استفاده از زبان برنامه نویسی سی پلاس یه سری داده به یک صفحه php بفرستم با متد GEt مثلا
آدرس صفحه وب و دادهام به صورت زیر تعریف می شوند.
کد HTML:
www.mysite.com/fun.php?username=admin&password=12345
حالا مثلا کد های اون صفحه پی اچ پی به صورت زیر باشه
<?php
$username=$_GET['username']
$password=$_GET['passworde']
?>
در واقع می خوام پارامترهایی که به این صفحه داده می شه در یک برنامه سی پلاس پلاس مقدار دهی بشه.
فقط نمی خوام که مرورگر سیستم بالا بیاد بره اون صفحه بلکه می خوام اتوماتیک این کار انجام بشه.
توی نت گشتم ولی از کداشون سر در نیوردم.
اگر کسی یه مثال کوچیک و جم و جور برام بزنه ممنونش میشم.
با تشکر فراوان
نقل قول: ارسال پارامتر به یک صفحه PHP با زبان برنامه نوسی C++
سلام
میتونید از کتابخانه curl استفاده کنید
این هم عین مثال خود کتابخونه:
//Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
#include <stdio.h>
#include <curl/curl.h>
int main(void)
{
CURL *curl;
CURLcode res;
/* In windows, this will init the winsock stuff */
curl_global_init(CURL_GLOBAL_ALL);
/* get a curl handle */
curl = curl_easy_init();
if(curl) {
/* First set the URL that is about to receive our POST. This URL can
just as well be a https:// URL if that is what should receive the
data. */
curl_easy_setopt(curl, CURLOPT_URL, "http://postit.example.com/moo.cgi");
/* Now specify the POST data */
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "name=daniel&project=curl");
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* Check for errors */
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
/* always cleanup */
curl_easy_cleanup(curl);
}
curl_global_cleanup();
return 0;
}
نقل قول: ارسال پارامتر به یک صفحه PHP با زبان برنامه نوسی C++
تو ويندوز ميتونيد از توابع API کتاب خونه WinInet استفاده کنيد
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <Windows.h>
#include <WinInet.h>
#pragma comment(lib, "wininet.lib")
using namespace std;
string OpenURL(const char *Url)
{
string strOut;
HINTERNET hSession = NULL;
HINTERNET hFile = NULL;
DWORD dwBytesRead = 0;
hSession = InternetOpenA("Mozilla/5.0", 1, NULL, NULL, 0);
if(!hSession)
{
return "";
}
hFile = InternetOpenUrlA(hSession, Url, NULL, NULL, INTERNET_FLAG_RELOAD | INTERNET_FLAG_DONT_CACHE, NULL);
if(!hFile)
{
//can't connect to host Url
InternetCloseHandle(hSession);
return "";
}
do {
char buffer[4000];
InternetReadFile(hFile, (LPVOID)buffer, sizeof(buffer), &dwBytesRead);
strOut.append(buffer, dwBytesRead);
} while (dwBytesRead);
InternetCloseHandle(hFile);
InternetCloseHandle(hSession);
return strOut;
}
void main()
{
string source = OpenURL("http://mysite.com/fun.php?username=admin&password=12345");
system("pause");
}
نقل قول: ارسال پارامتر به یک صفحه PHP با زبان برنامه نوسی C++
خیلی ممنون دوستان لطف بزرگی کردین:قلب:
1 ضمیمه
مشکلی در curl در زبان سی پلاس پلاس
سلام
نمیخواستم تایپیک جدید الکی ایجاد کنم
و چون کدشم مربوط به این تایپیک بود همینجا میگم.
یک مشکلی در curl دارم
کد :
#include <urlmon.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <wininet.h>
#include <iomanip>
#include <windows.h>
#include <fstream>
#include <sstream>
#include <curl/curl.h>
#include <stdio.h>
#include <stdlib.h>
#include <curl/curl.h>
#include <curl/easy.h>
#include <WinInet.h>
#pragma comment(lib, "wininet.lib")
using namespace std;
int main()
{
string OpenURL(std::string);
cout << OpenURL("http://www.google.com/");
getchar();
return 0;
}
string OpenURL(const char *Url)
{
string strOut;
HINTERNET hSession = NULL;
HINTERNET hFile = NULL;
DWORD dwBytesRead = 0;
hSession = InternetOpenA("Mozilla/5.0", 1, NULL, NULL, 0);
if (!hSession)
{
return "";
}
hFile = InternetOpenUrlA(hSession, Url, NULL, NULL, INTERNET_FLAG_RELOAD | INTERNET_FLAG_DONT_CACHE, NULL);
if (!hFile)
{
//can't connect to host Url
InternetCloseHandle(hSession);
return "";
}
do {
char buffer[4000];
InternetReadFile(hFile, (LPVOID)buffer, sizeof(buffer), &dwBytesRead);
strOut.append(buffer, dwBytesRead);
} while (dwBytesRead);
InternetCloseHandle(hFile);
InternetCloseHandle(hSession);
return strOut;
}
کد رو از لینک:
https://barnamenevis.org/showthread.p...light=curl+cpp
کمک گرفتم.
ضمیمه 139549
نقل قول: ارسال پارامتر به یک صفحه PHP با زبان برنامه نوسی C++
من درمورد این توابع سوال دارم.
InternetOpenA
InternetOpenurlA
پارامتر هاش چیه؟
توی این مثال کدوم متغیر ها به صفحه php ارسال شده؟
من با wampserver کارمیکنم. میتونم این کدو براش استفاده کنم؟