<?php
echo '<html><head><title></title></head><body>
';
echo $_POST["myvar"];
echo '</p></body></html>';
?>
problem of sending data with the POST method
I have the index2.php in my http server directory which prints the myvar variables value.
Код:
This thing is working fine when I post data from the index2.htm file,
Код:
<html><head><title>My PHP Query Page</title></head><body>
<center>
<form action="index2.php" method="post">
<input type="text" name="myvar">
<input type="submit" value="Submit Query">
<input type="reset" value=" Reset ">
</p></form>
</center>
</body></html>
<center>
<form action="index2.php" method="post">
<input type="text" name="myvar">
<input type="submit" value="Submit Query">
<input type="reset" value=" Reset ">
</p></form>
</center>
</body></html>
but it doesn't work when I try to post some data using HttpOpenRequest(...), HttpSendRequest(...) WinINET APIs.
Код:
#include <windows.h>
#include <wininet.h>
#include <iostream>
using std::cout;
void main()
{
HINTERNET hInternet = InternetOpen(
"MyAgent",
INTERNET_OPEN_TYPE_DIRECT,
NULL,
NULL,0);
cout<<"hInternet="<<(int)hInternet<<"\nGetLastError()="<<GetLastError()<<"\n\n";
HINTERNET hConnect = InternetConnect(
hInternet,
"127.0.0.1",
80,
NULL,
NULL,
INTERNET_SERVICE_HTTP,
0,
0);
cout<<"hConnect="<<(int)hConnect<<"\nGetLastError()="<<GetLastError()<<"\n\n";
LPCTSTR AcceptTypes[] = { TEXT("*/*"), NULL};
HINTERNET hRequest = HttpOpenRequest(
hConnect,
"POST",
"/index2.php",
NULL,
NULL,
AcceptTypes,
INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RELOAD | INTERNET_FLAG_PRAGMA_NOCACHE,
0);
cout<<"hRequest="<<(int)hRequest<<"\nGetLastError()="<<GetLastError()<<"\n\n";
char optData[] = "?myvar=31";
BOOL retRes = HttpSendRequest(
hRequest,
0,
0,
optData,
lstrlen(optData)
);
cout<<"retRes="<<(int)retRes<<"\nGetLastError()="<<GetLastError()<<"\n\n";
auto char buffer[4096];
auto DWORD uLong;
if(InternetReadFile(hRequest,buffer,4096,&uLong) == FALSE){
MessageBox(0,"ERROR InternetReadFile returns NULL","ERROR",0);
return;
}
for(UINT i=0;i<uLong;i++){
cout<<buffer;
}
Sleep(20000);
}
#include <wininet.h>
#include <iostream>
using std::cout;
void main()
{
HINTERNET hInternet = InternetOpen(
"MyAgent",
INTERNET_OPEN_TYPE_DIRECT,
NULL,
NULL,0);
cout<<"hInternet="<<(int)hInternet<<"\nGetLastError()="<<GetLastError()<<"\n\n";
HINTERNET hConnect = InternetConnect(
hInternet,
"127.0.0.1",
80,
NULL,
NULL,
INTERNET_SERVICE_HTTP,
0,
0);
cout<<"hConnect="<<(int)hConnect<<"\nGetLastError()="<<GetLastError()<<"\n\n";
LPCTSTR AcceptTypes[] = { TEXT("*/*"), NULL};
HINTERNET hRequest = HttpOpenRequest(
hConnect,
"POST",
"/index2.php",
NULL,
NULL,
AcceptTypes,
INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RELOAD | INTERNET_FLAG_PRAGMA_NOCACHE,
0);
cout<<"hRequest="<<(int)hRequest<<"\nGetLastError()="<<GetLastError()<<"\n\n";
char optData[] = "?myvar=31";
BOOL retRes = HttpSendRequest(
hRequest,
0,
0,
optData,
lstrlen(optData)
);
cout<<"retRes="<<(int)retRes<<"\nGetLastError()="<<GetLastError()<<"\n\n";
auto char buffer[4096];
auto DWORD uLong;
if(InternetReadFile(hRequest,buffer,4096,&uLong) == FALSE){
MessageBox(0,"ERROR InternetReadFile returns NULL","ERROR",0);
return;
}
for(UINT i=0;i<uLong;i++){
cout<<buffer;
}
Sleep(20000);
}
The server respond like it doesn't receive any data.
Код:
<html><head><title></title></head><body>
Warning: Undefined index: myvar in D:\!!HTTP!!\WWW\index2.php on line 4
</p></body></html>
Warning: Undefined index: myvar in D:\!!HTTP!!\WWW\index2.php on line 4
</p></body></html>
I posted the optData string with the InternetSendRequest(...)
optData[] = "?myvar=31";
is it right ?
what I made wrong ?
Цитата:
Originally posted by BlackCode
echo $_POST["myvar"];
echo $_POST["myvar"];
Англичанин блин ))
Try to declare a myvar variable like
global $myvar
If myvar not declared in query it will be empty
$myvar = ""
If you need a specified POST protocol you should check array $_POST (I do not remember how to do it but try to download PHPExpertEditor. This is very useful program with APACHE with PHP on-board and all PHP functions list)
Editor URLs:
http://www.phpexperteditor.com/
http://www.expertedit.com/
http://www.ankord.com/
Цитата:
Originally posted by BlackCode
вообще то я армянин :devil:
вообще то я армянин :devil:
А зачем по-английски ))
На sources, похоже, уже ответили