Go Back   Armenian Knowledge Base > Technical sections > Languages, Compilers, Interpreters

Reply
 
Thread Tools

problem of sending data with POST method
Old 09.05.2005, 16:47   #1
incomer
 
BlackCode's Avatar
 
Join Date: 02 2005
Location: Yerevan
Age: 40
Posts: 16
Rep Power: 0
Question problem of sending data with POST method

I have Apache2 server and PHP4 installed on my local computer for educational purposes.

I have the index2.php in my http server directory which prints the myvar variables value.
Code:
<?php 

echo '<html><head><title></title></head><body><p>';
echo $_POST["myvar"];
echo '</p></body></html>';

?>
This thing is working fine when I post data from the index2.htm file,

Code:
<html><head><title>My PHP Query Page</title></head><body><br><br><center>

<form action="index2.php" method="post">
<p> <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.

Code:
#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[i];
	}

	Sleep(20000);
}
The server respond like it doesn't receive any data.

Code:
<html><head><title></title></head><body><p><br>
<b>Warning</b>:  Undefined index:  myvar in <b>D:\!!HTTP!!\WWW\index2.php</b> on line <b>4</b><br>
</p></body></html>
I posted the optData string with the InternetSendRequest(...)

optData[] = "?myvar=31";

is it right ?
what I made wrong ?
__________________
Regards, Aram
Reply




Реклама:
реклама
Buy text link .

All times are GMT. The time now is 12:32.
Top

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.