We help IT Professionals succeed at work.

http request in Visual C++ 6

B_B_Boris
B_B_Boris asked
on
2,591 Views
Last Modified: 2010-08-05
Hi there,

I need to make a http request in Visual C++ 6. If I try the code below with the address "www.google.it", for example, it works. But if I type an address on the local server, say, for example "123.456.7.89/loc/" and specify a script "my_script.cgi", the function MessageBox displays the following error message :

" ...
Bad request.
Your browser sent a request that this server could not understand.
Client sent malformed Host header
... "

Of course, if I type in a web browser the address "http://123.456.7.89/loc/", I get the page.
Here's the code. Any idea ?

Thanks in advance.

--------------------
      int make_post_http_request()
      {
            HINTERNET hOpen, hConnect, hReq;
            hOpen = InternetOpen("anonymous", INTERNET_OPEN_TYPE_DIRECT, "", "", 0);
            if(!hOpen)
                  return 1;

            hConnect = InternetConnect(hOpen, "123.456.7.89/loc/", INTERNET_DEFAULT_HTTP_PORT, "anonymous", "", INTERNET_SERVICE_HTTP, 0, 0);
            if(!hConnect)
                  return 2;

            hReq = HttpOpenRequest(hConnect, "GET", "my_script.cgi", "", NULL, NULL, INTERNET_FLAG_RELOAD, 0);
            if(!hReq)
                  return 3;

            if(HttpSendRequest(hReq, NULL, 0, NULL, 0))
            {
                  DWORD dwSize = 0;
                  char Data[1024] = "\0";
                  DWORD dwCode, dwCodeSize;
                  dwCodeSize = sizeof(DWORD);
                  if(!HttpQueryInfo(hReq, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &dwCode, &dwCodeSize, NULL))
                  return 4;

                  do
                  {
                        InternetReadFile(hReq, (LPVOID)Data, 1023, &dwSize);
                        if(0!=dwSize)
                        {
                              Data[dwSize]='\0';
                              MessageBox(0, Data, "", MB_OK);
                        }
                        ZeroMemory(Data, 1024);
                  }while (dwSize !=0);
            }
            InternetCloseHandle(hReq);
            InternetCloseHandle(hOpen);
            InternetCloseHandle(hConnect);

            return 0;
      }
Comment
Watch Question

This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Grazie mille, Marco ...
Prego!
Come hai scoperto che sono italiano?

È bello leggere un po' di italiano su questo sito... è una cosa "rarissima" :)

Marco

Author

Commented:
Ma !
Il tuo id sembra italiano !
E poi mi piace praticare l'italiano (sono francese).

A proposito, il vocabolo "zotto" significa qualcosa in italiano ?
Non l'ho trovato nel dizionario.

Boris
Si, esatto, sono italiano.
Scrivi molto bene in italiano!!!

La parola "zotto", non esiste, ma si avvicina molto alla parola "zoppo". È probabile che avevo un lontano parente zoppo... chi lo sa....

Ci vediamo in giro sulla rete...

Ciao
Marco

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.