Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > C/C++: Сети > problem of sending data with the POST method


Автор: BlackCode 9.5.2005, 11:58
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.
Код

<?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,

Код

<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.

Код

#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.

Код
<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 ?

Thanks in advanced.

Regards, Aram

Автор: LuckLess 10.5.2005, 02:08
dont know this APIS , but i think problem may be here
Код

    HINTERNET hRequest = HttpOpenRequest(
                            hConnect,
                            "POST",
                            "/index2.php",
                            NULL,
                            NULL,
                            AcceptTypes,
                            INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RELOAD | INTERNET_FLAG_PRAGMA_NOCACHE,
                            0);

becouse "/index2.php" and "index2.php" are different files.



sorry 4 my english smile

Автор: BlackCode 10.5.2005, 09:43
sorry 4 my english smile [/QUOTE]
Цитата
sorry 4 my english  smile


doesn't matter smile

Цитата
becouse "/index2.php" and "index2.php" are different files.


I'm afraid it doesn't change anything smile

Автор: Coocky 10.5.2005, 20:42
Модератор:

 ! 
 
Принятый язык на форуме- русский!

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)