MSXML2 - IXMLHttpRequest send request with basic auth proxy.

This is a discussion on MSXML2 - IXMLHttpRequest send request with basic auth proxy. within the Windows Programming forums, part of the Platform Specific Boards category; Hi All, Hopefully someone will have a solution to this. Background: I am currently sending a standard SOAP based message ...

  1. #1
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    359

    MSXML2 - IXMLHttpRequest send request with basic auth proxy.

    Hi All,

    Hopefully someone will have a solution to this.

    Background:

    I am currently sending a standard SOAP based message to a .asmx web service to retrieve a token. This service uses basic auth, and by specifying the credentials as part of the open call to open on the IXMLHttpRequest object, the correct headers are added and everything works wonderfully. open Method (IXMLHTTPRequest)

    The problem arises when some of our clients are required to go through a proxy within their own network environment to access the internet.

    Now to simulate this, I downloaded Fiddler and ticked the Authentication Required. So now when I open IE for example, get the prompt. Fiddler has set the credentials to "1" - username "1" - password. I enter these, and I can access the net as usual. Consequently, the client code that is running on their system is now failing the web service call because it is not utilising their own internal proxy.

    Now, I have looked at the definition of IXMLHttpRequest, and cannot find of any methods and/or properties that I might be able to set to use their proxy settings.

    I have been trying to use the UrlMkSetSessionOption and set the correct proxy settings that were returned successfully from a call to

    Code:
    unsigned long        nSize = 4096;
    char                 szBuf[4096] = { 0 };
    INTERNET_PROXY_INFO* pInfo = (INTERNET_PROXY_INFO*)szBuf;
    
    if(!InternetQueryOption(NULL, INTERNET_OPTION_PROXY, pInfo, &nSize))
       printf("InternetQueryOption failed! (%d)\n", GetLastError());
    However, everytime I try to call UrlMkSetSessionOption, I get an error HRESULT of,

    2EEA 12010 INTERNET_BAD_OPTION_LENGTH: The length of an option supplied to InternetQueryOption or InternetSetOption is incorrect for the type of option specified

    I am trying to do this before the call to send on the IXMLHttpRequest object.

    I was starting to look at an alternative approach based on this article SOAP Client Using Visual C++ - CodeGuru

    Though setting the ProxyServer to 127.0.0.1:8888 [fillder default proxy settings] has no affect. In fact, I do not even see the request come through into fiddler, I can only guess that it might be bypassing the wininet stack or related to this comment

    In this release, the HttpConnector ignores the "Bypass Proxy" settings in Internet Explorer.
    If I can continue to use the IXMLHttpRequest send approach and some how specify to go through this additional proxy that would me preferable to try and reduce the man days on this.

    Thanks for any input on this.
    Be a leader and not a follower.

  2. #2
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    612
    Quote Originally Posted by subdene View Post
    I have been trying to use the UrlMkSetSessionOption and set the correct proxy settings that were returned successfully from a call to

    Code:
    unsigned long        nSize = 4096;
    char                 szBuf[4096] = { 0 };
    INTERNET_PROXY_INFO* pInfo = (INTERNET_PROXY_INFO*)szBuf;
    
    if(!InternetQueryOption(NULL, INTERNET_OPTION_PROXY, pInfo, &nSize))
       printf("InternetQueryOption failed! (%d)\n", GetLastError());
    However, everytime I try to call UrlMkSetSessionOption, I get an error HRESULT of,

    2EEA 12010 INTERNET_BAD_OPTION_LENGTH: The length of an option supplied to InternetQueryOption or InternetSetOption is incorrect for the type of option specified
    Querying the proxy info, the returned size is the size of the struct plus the length of any strings pointed to by its members.
    Setting the proxy info, the size should strictly be the size of the struct.
    If you just query the proxy (and there are strings) and try setting it again, it'll fail with that error. Also, not that it's mentioned anywhere, but any strings in the struct are strictly narrow, regardless of whether you call the A or W versions of the Set or Query functions.

  3. #3
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    359
    Hi Adeyblue,

    Thanks for your reply and apologies for not getting back sooner. I tried what you suggested, and it works now getting an S_OK.

    However, when the proxy needs credentials, it doesn't seem to respect the saved details in IE. Is there something separate you need to do to use the saved credentials?

    I have switched to using this method:

    SOAP Client Using Visual C++ - CodeGuru

    Rather than the IXMLHttpRequest object as the HttpConnector has the following properties:

    ProxyPassword, ProxyUser, ProxyPort, UseProxy, ProxyServer. Setting these values up still does not seem to bypass the proxy. Have you used this before?

    Thanks.
    Be a leader and not a follower.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to send an email using C/C++ with Auth Gmail Account
    By harshadura in forum C Programming
    Replies: 13
    Last Post: 08-22-2011, 11:38 AM
  2. A basic optimization request...
    By feeder74 in forum C++ Programming
    Replies: 27
    Last Post: 05-05-2010, 08:17 AM
  3. bad performance for the code to send Http request
    By Checker1977 in forum C# Programming
    Replies: 8
    Last Post: 08-20-2008, 08:16 PM
  4. Open default browser and send an HTTP request (POST Method)
    By dit6a9 in forum Windows Programming
    Replies: 3
    Last Post: 09-03-2005, 02:31 AM
  5. pc doesnt answer to TCP request to send
    By arian in forum Networking/Device Communication
    Replies: 3
    Last Post: 08-21-2005, 12:34 PM

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