0

So i did this simple exemple : I send a http request from a client PC that execute a php script on raspberry Pi to count the number of files in a directory then a second request that execute a php script to delete them and then the first script again to ensure that it worked.

The problem is that the second time I ask for the number of files, it return the result of the first time I called the function, also the script to delete the files worked. I used wireshark on the network and I actually see that the second request to count the file is not send, I don't understand why, is it my code ? or from the http protocole ?

Here is my code, there is only the 2 requests to count the number of ADL files, only with this i can see on wireshark that just on request is send :

#include "MA_DLLCPP.h"
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <wininet.h>
#include <string.h>


 int main(int argc, char* argv[])
{
    int error = 0;
char* result = 0;
DWORD dwBytes;
char ch [100] = "0";
char ligne [100] = "";
char ligne1 [100] = "";
HINTERNET Initialize,Connection,File;

//Création de la session internet
Initialize = InternetOpenA("pi",INTERNET_OPEN_TYPE_DIRECT,"","",0);

if(Initialize == NULL) return 1;

//Connection HTTP serveur-client
Connection =                                      InternetConnectA(Initialize,"192.168.1.2",INTERNET_DEFAULT_HTTP_PORT,
        NULL,NULL,INTERNET_SERVICE_HTTP,0,0);




strcat(ligne, "IHM_DLD/services/");
strcat(ligne, "getADL");
strcat(ligne, ".php");

//Création de la requete HTTP
    File = HttpOpenRequestA(Connection, "GET",ligne,NULL,NULL,NULL,0,0);

    if(File == NULL) return 3;


    //Envoi de la requete HTTP
    if(HttpSendRequestA(File,NULL,0,NULL,0) == FALSE) return 4;

    //Lecture de la réponse du serveur
    if(InternetReadFile(File,&ch,1,&dwBytes) == FALSE) return 5;

    while(InternetReadFile(File,&ch,1,&dwBytes))
    {
        // cas d'erreur en cas d'absence de retour
        if(dwBytes != 1) break;

        printf("%s",ch);

    }


InternetCloseHandle(File);
InternetCloseHandle(Connection);
InternetCloseHandle(Initialize);

//Connection HTTP serveur-client
    Connection = InternetConnectA(Initialize,"192.168.1.2",INTERNET_DEFAULT_HTTP_PORT,
            NULL,NULL,INTERNET_SERVICE_HTTP,0,0);

//Création de la requete HTTP
        File = HttpOpenRequestA(Connection, "GET",ligne,NULL,NULL,NULL,0,0);

        if(File == NULL) return 3;


        //Envoi de la requete HTTP
        if(HttpSendRequestA(File,NULL,0,NULL,0) == FALSE) return 4;

        //Lecture de la réponse du serveur
        if(InternetReadFile(File,&ch,1,&dwBytes) == FALSE) return 5;

        while(InternetReadFile(File,&ch,1,&dwBytes))
        {
            // cas d'erreur en cas d'absence de retour
            if(dwBytes != 1) break;

            printf("%s",ch);

        }




InternetCloseHandle(File);
InternetCloseHandle(Connection);
InternetCloseHandle(Initialize);

1 Answers1

0

Sounds like a chaching effect to me. The second time the request is handled locally on your machine.

I have never used it but passing INTERNET_FLAG_NO_CACHE_WRITE within the dwFlags parameter of HttpOpenRequest looks like it should do the trick...

You may also look at this post: How to clear MSIE/WinInet cache programatically?

Community
  • 1
  • 1
Lukas Thomsen
  • 3,089
  • 2
  • 17
  • 23