need help using wininet

This is a discussion on need help using wininet within the Windows Programming forums, part of the Platform Specific Boards category; i am just trying to connect to google with inet functions with a small console app and for some reason ...

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    315

    need help using wininet

    i am just trying to connect to google with inet functions with a small console app and for some reason its printing 9 chars to console only and not the whole html page , thanks if you can help

    Code:
    #include "stdafx.h"
    #include <windows.h>
    #include <Wininet.h>
    #include <stdio.h>
    
    #pragma comment(lib,"Wininet.lib")
    
    int main
    {
    
    	char NetBuffer[4000],NetBufferToWrite[5000],NetBuildToWrite[5000];
    	DWORD NetRead,NetToRead;
    	DWORD NetWrite,NetToWrite;
    
    	HINTERNET Net = InternetOpen("Broswer:",
    		           INTERNET_OPEN_TYPE_DIRECT,//INTERNET_OPEN_TYPE_PROXY, //INTERNET_OPEN_TYPE_DIRECT
    				   NULL,//"socks=66.57.195.229:38671",
    				   NULL,
    				   NULL);//INTERNET_FLAG_ASYNC);
    
    	if(Net == NULL)
    	{
    	    printf("%s\n","Something Went Wrong With Proxy Configuration");
    		printf("%d\n",GetLastError());
    		Sleep(5000);
    	}
    	else
    	{
    		//printf("%s\n","Proxy Connection Set!");
    
        
    		HINTERNET NetOpen = InternetOpenUrl(Net,
    			"http://google.co.uk", //
    						     NULL,
    						        NULL,
    				   INTERNET_FLAG_KEEP_CONNECTION,
    				            INTERNET_NO_CALLBACK);
    				                          
    
    		if(NetOpen == NULL)
    		{
    			printf("%s\n","Failed to Connect To Url");
    			printf("%d\n",GetLastError()); //returns 997
    		}
    		else
    		{
    			printf("%s\n","Connected to Url");
    			Sleep(5000);
    			
    			
    
    				   Sleep(5000);
    				
    				
    
    				//char *GetMain = "GET / HTTP/1.1\r\n"
    			    LPCSTR Accept("text/*");
    				HINTERNET NetRequest = HttpOpenRequest(NetOpen,
    					            "GET", //verbname GET/POST
    								NULL, //objectname
    								NULL, //http version 1.1
                                    NULL, //refefer
    								&Accept, //type to accept
    								INTERNET_FLAG_RELOAD | INTERNET_FLAG_KEEP_CONNECTION,
    								NULL);
    
    				HttpSendRequest(NetRequest,
    					                  NULL,
    									  NULL,									  
    									  NULL,
    									  NULL);
    
    			  InternetReadFile(NetOpen,NetBuffer,NetRead,&NetToRead);
    			  printf("%s %d\n","Number of Byte To Read",NetRead);
    		      printf("%s %d\n",NetBuffer,strlen(NetBuffer));
    
    			  }
    	
    	}
    
    	
    
    	Sleep(5000);
    
    	return 0;
    }

  2. #2
    Registered User
    Join Date
    May 2008
    Location
    Australia
    Posts
    230
    You have no InternetReadFile loop:

    To ensure all data is retrieved, an application must continue to call the InternetReadFile function until the function returns TRUE and the lpdwNumberOfBytesRead parameter equals zero.
    http://msdn.microsoft.com/en-us/libr...03(VS.85).aspx

    Oh and your code is hard to read due to indentation
    Last edited by pobri19; 04-03-2009 at 09:34 PM.
    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. wininet
    By jopp3 in forum C Programming
    Replies: 0
    Last Post: 04-29-2007, 09:27 AM
  2. My tut on WinINet...
    By Queatrix in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 04-24-2007, 11:33 AM
  3. Using wininet with cookies
    By bithub in forum Windows Programming
    Replies: 4
    Last Post: 06-01-2006, 10:10 PM
  4. wininet (internetconnect)
    By jabroni77 in forum Networking/Device Communication
    Replies: 0
    Last Post: 05-19-2005, 07:29 AM
  5. Where can i find a tutorial on WinInet?
    By Inquirer in forum C++ Programming
    Replies: 1
    Last Post: 04-24-2002, 04:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21