Getting the source url from http response RRS feed

  • Question

  • hi,

     I am sending an http request to a device( eg: from a C++ Metro style app. I am getting the response also. I am using IXMLHttpRequest2 interface..But on getting a response from the device, I need to go to another web page of the device and read info from there. ie. On getting the OnHeadersAvailable() method of the callback, I need to request another page ( eg: of the device .In order to do this, I need to know from which IP the response came from. Of course we know that the response in this case comes from the IP to which we made the http request. Since I am using IXMLHTTPRequest2Callback-derived class to get the response callbacks, there is no way I can track the requested IP since the caller and callbacks are in two classes.  I am working with a number of IPs in this manner which are not known in advance. Thats why I need to get the IP from which the response came.  For each IP I am working with, I need to make two requests per IP. Is there any way we can get the IP? Can we get the IP from the HTTPRequest parameter of OnHeadersAvailable() method in callback?

    If no option, can we get it using cookies? ie. setting a cookie like (url-url value pair) to the httprequest before the request is sent and getting the cookie using GetCookies() method and read the url we set in the request when we receive the response. That way I think we can track the IP in the callback. I tried but there is not much info/sample on setting/getting cookies using XHR_COOKIE . I dont know if at all cookies can be used for that purpose.

    Any info how we can do this? Below is how my callback looks like:

    IFACEMETHODIMP CallBackHandler::OnHeadersAvailable(IXMLHTTPRequest2 *pXHR, DWORD dwStatus, const wchar_t *pwszStatus)
        WCHAR* pszHeaderVal;
        pXHR->GetAllResponseHeaders(&pszHeaderVal );

        std::wstring Response( pszHeaderVal );

        // Get the Server in the response.
        int nPos = Response.find(L"Server: " );
        if( server =="some val" )
            send an http request to soure ip://somepage.xml
        return S_OK;

    Thanks in advance..

    Monday, May 14, 2012 3:43 PM


All replies

  • Hello,


    Thanks for your feedback, I will involve more experts to investigate it.


    Best regards,


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, May 15, 2012 8:37 AM
  • Hi Its,

    You will need to keep track of the URL you are sending to externally.  You will not be able to effectively use cookies and this interface does not expose the URL as a property.


    Jeff Sanders (MSFT)

    Tuesday, May 15, 2012 11:54 AM
  • Thank you for your replies. I am keeping track of the url in my code now.
    Tuesday, May 15, 2012 1:50 PM