locked
how can I make a network request in c++? RRS feed

  • Question

  • I'm working on a project which is composed of two parts:processing part-written in c++, and UI part-written in asp.net c#. I made an http request from the c++ project to a page in the asp.net part. the problem is that I don't know how to add a reference to the web project(a page in it) in my c++ project, so the c++ part could communicate with the c# part. http request will be executed well.

    Do you know how I can make the c++ part know the asp.net page(something like add web reference in c#,but now I need that in c++).

    I wrote the following code of the http request in c++:

     HINTERNET handle = InternetOpen("Upload", INTERNET_OPEN_TYPE_DIRECT,     
              NULL, NULL, 0);
    if (handle)
    {
    
        HINTERNET handleConnect = 
                        InternetConnect(handle, "localhost:4653/webservice.asmx", 
                                 INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, 
                                 INTERNET_SERVICE_HTTP, NULL, NULL);
        if (handleConnect)
        {
            if (HINTERNET handleOpenReq = 
                            HttpOpenRequest(handleConnect, TEXT("POST"), 
                                   TEXT("/HelloWorld"), NULL, NULL, NULL, 
                                   INTERNET_FLAG_KEEP_CONNECTION, 0))
            {
                if (HttpSendRequest(handleOpenReq, NULL, 0, NULL 
                                                 ,0))
                    cout << "ddddd" << endl;
                else
                {
                    DWORD p = GetLastError();
                    int a = 9;
                }
            }
    
        }
    }

    but httpsendrequest returns 0. I think that's because I have no a reference to my asp.net project..am I right? if so, How could I add that? thanks

    Tuesday, December 15, 2015 7:14 AM

Answers

  • Hi,

    Thanks for posting here.

    Could you please tell what result you get from GetLastError method?

    Before you run the C++ code above, I think you shoud check if the asp.net website published to server correctly. If you can access the asp.net page through web browser successfully.

    >Do you know how I can make the c++ part know the asp.net page(something like add web reference in c#,but now I need that in c++).

    They don't need any reference I think. You need to make sure the web service is deployed well.

    When I use your code to access another web page,e.g www.microsoft.com , the httpsendrequest method can return well. So C++ code part is ok for me. You may also check what is the reponse  message feedback from server, if there is wrong format. There is a similar thread in link below you may refer to.

    Server received all data but HttpSendRequest return FALSE 12002 in client

    May


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    Wednesday, December 16, 2015 1:36 PM