locked
How to make internet connection using "InternetConnect" api RRS feed

  • Question

  • Hi,

     

    In my app I need to make connection to address like that:

     http://x.y.z.w:8080/a/b 

    I make the following calls:

    HINTERNET hIntConnectPost;
     hIntConnectPost = InternetConnect( hIntOpen,
      L"x.y.z.w:8080",
      INTERNET_DEFAULT_HTTP_PORT, 
      L"",    // username
      L"",    // password
      INTERNET_SERVICE_HTTP,
      0,   // no flags
      NULL); // no context

     const TCHAR* lplpszAcceptTypes[] = {L"text/xml",L"application/xml",L"application/xhtml+xml",L"text/html;q=0.9",
      L"text/plain;q=0.8",L"image/png",L"*/*;q=0.5", NULL};

     DWORD connFlags = INTERNET_FLAG_KEEP_CONNECTION;
     unsigned short URL_CALL[200] = {L"/gts/gtapi"};
     
     HINTERNET hHttpOpenReq = HttpOpenRequest(
      hIntConnectPost,
      L"POST",
      URL_CALL,
      HTTP_VERSION,
      NULL,
      (LPCTSTR *) lplpszAcceptTypes,
      connFlags,
      0);

     if(!HttpAddRequestHeaders(hHttpOpenReq,
      L"Content-Type: application/x-www-form-urlencoded",
      -1,
      HTTP_ADDREQ_FLAG_REPLACE | HTTP_ADDREQ_FLAG_ADD))
     {
      .....
     }

     char lpOptional[1000] = {'\0'};
     strcpy(lpOptional,   "<?xml version=\"1.0\" encoding=\"utf-8\"...xml request..<username>");
     

     int len= strlen(lpOptional);
     BOOL bRes = HttpSendRequest(hHttpOpenReq, NULL, 0, (LPVOID)lpOptional, len);  
     if (!bRes)
     {
      DWORD conErr = GetLastError(); //Possible values are from format of INTERNET_ERROR_BASE + XXX

    ......

    I got failure after calling : "HttpSendRequest" api.

    my XML request & all other api's requests are valid.

    I got  error code: 12029 after calling: "GetLastError".

    What do I do wrong.

    How should I attach the port number to server address?

    tnx

     

    Wednesday, July 28, 2010 12:53 PM

All replies

  • Hi,

    Firstly, please test the url in PIE and check whether the url is available in PIE.

    Please also close firewall and check it again.

     

    If you still can't solve it, please let me know.

     

    Best regards,
    Guang-Ming Bian - MSFT


    Please remember to mark the replies as answers if they help and unmark them if they provide no help
    Friday, July 30, 2010 6:24 AM