编程提交表单
程序员文章站
2022-06-03 21:10:15
...
char accept[] = "Accept: */*";
char frmdata[] = "param1=str1¶m2=str2¶m3=str3";
HINTERNET hSession = InternetOpen("MyAgent", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
HINTERNET hConnect = InternetConnect(hSession, "www.target.com", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1);
HINTERNET hRequest = HttpOpenRequest(hConnect, "POST", "filename.php", NULL, NULL, (LPCSTR *)&accept, INTERNET_FLAG_NO_COOKIES , 1);
HttpSendRequest(hRequest, "Content-Type: application/x-www-form-urlencoded", -1, (LPVOID)frmdata, sizeof(frmdata));
InternetCloseHandle(hRequest);
InternetCloseHandle(hConnect);
InternetCloseHandle(hSession);
说明:
char frmdata[] = "param1=str1¶m2=str2¶m3=str3";
HINTERNET hSession = InternetOpen("MyAgent", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
HINTERNET hConnect = InternetConnect(hSession, "www.target.com", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1);
HINTERNET hRequest = HttpOpenRequest(hConnect, "POST", "filename.php", NULL, NULL, (LPCSTR *)&accept, INTERNET_FLAG_NO_COOKIES , 1);
HttpSendRequest(hRequest, "Content-Type: application/x-www-form-urlencoded", -1, (LPVOID)frmdata, sizeof(frmdata));
InternetCloseHandle(hRequest);
InternetCloseHandle(hConnect);
InternetCloseHandle(hSession);
说明:
frmdata为表单数据,其中表单参数用&隔开;
HttpOpenRequest的第二个参数使用POST,表示提交表单。
上一篇: php中日期时间的比较,该怎么解决