none
WinHTTPSetOption and "remove" option issue?

    Question

  • Hi,

    i need some help with WinHTTPSetOption and "remove" option what is set by WinHTTPSetOption.

    I need to "unset" this options:

    first if i receive an error WINHTTP_CALLBACK_STATUS_SECURE_FAILURE i set this options,

    myFeature = SECURITY_FLAG_IGNORE_CERT_CN_INVALID | SECURITY_FLAG_IGNORE_CERT_DATE_INVALID | SECURITY_FLAG_IGNORE_UNKNOWN_CA;
    fRet = WinHttpSetOption(m_hRequest, WINHTTP_OPTION_SECURITY_FLAGS, &myFeature, sizeof(myFeature));

    now i like to "unset"  the same options but all my trys they dont works :(.

    This is what i try before:

    fRet = WinHttpSetOption( m_hRequest, WINHTTP_OPTION_DISABLE_FEATURE, &myFeature, sizeof(myFeature));

    but the options are active until i close my application?

    Thanks for any help!

    Best regards

    mirso_h

    Friday, May 10, 2013 2:40 PM

Answers

  • On 5/15/2013 11:01 AM, mirso_h wrote:

    thanks for reply, now, after i ignore this error for first, like to receive this again, so "in my own words" to enable this errors again, to catch them, and this is disabled for the rest of my session until i close my application and start them again.

    What handle are you setting the option on? How is m_hRequest obtained? If it's actually a request handle - that is, obtained with WinHttpOpenRequest - then you can only use it once, for a single request. After that request completes, setting options on this request handle is pointless - you can't use it again anyway. The only meaningful thing you can do with it is close it, using WinHttpCloseHandle.

    You need to obtain a new request handle with WinHttpOpenRequest for each request you want to make, and set options on it as needed.

    On the other hand, if you set the option on the session handle (obtained with WinHttpOpen) or connection handle (obtained with WinHttpConnect), then the option would be inherited by every request handle created within that session or connection. Changing the option on the session handle would affect new requests created afterwards, but not request handles that are already created.


    Igor Tandetnik

    Wednesday, May 15, 2013 4:30 PM

All replies

  • On 5/10/2013 10:40 AM, mirso_h wrote:

    i need some help with WinHTTPSetOption and "remove" option what is set by WinHTTPSetOption.

    I need to "unset" this options:

    first if i receive an error WINHTTP_CALLBACK_STATUS_SECURE_FAILURE i set this options,

    myFeature = SECURITY_FLAG_IGNORE_CERT_CN_INVALID | SECURITY_FLAG_IGNORE_CERT_DATE_INVALID | SECURITY_FLAG_IGNORE_UNKNOWN_CA;
    fRet = WinHttpSetOption(m_hRequest, WINHTTP_OPTION_SECURITY_FLAGS, &myFeature, sizeof(myFeature));

    now i like to "unset"  the same options but all my trys they dont works :(.

    Just call WinHttpSetOption again, with myFeature set to 0.

    You don't "remove" the option - you just set it to the combination of flags that you want to be on (all others will be off). In particular, the value of 0 means that all flags are off.


    Igor Tandetnik

    Friday, May 10, 2013 5:46 PM
  • Hi,

    thanks for Answer, but i'm still confuse, can you give me some code snippet?

    Did you mean like this:

    myFeature = 0;

    WinHttpSetOption(m_hRequest, WINHTTP_OPTION_SECURITY_FLAGS, &myFeature, sizeof(myFeature));

    this dont work. :(

    Best regards

    mirso_h

    Monday, May 13, 2013 7:50 AM
  • On 5/13/2013 3:50 AM, mirso_h wrote:

    Did you mean like this:

    myFeature = 0;

    WinHttpSetOption(m_hRequest, WINHTTP_OPTION_SECURITY_FLAGS, &myFeature, sizeof(myFeature));

    this dont work. :(

    Doesn't work in what way? What behavior do you expect, what outcome do you observe, and how does the former differ from the latter?


    Igor Tandetnik

    Monday, May 13, 2013 1:20 PM
  • Hi,

    thanks for reply, now, after i ignore this error for first, like to receive this again, so "in my own words" to enable this errors again, to catch them, and this is disabled for the rest of my session until i close my application and start them again.

    Hope this is understandable because English is not my native language :(

    Thanks for answer and help!

    mirso_h

    Wednesday, May 15, 2013 3:01 PM
  • On 5/15/2013 11:01 AM, mirso_h wrote:

    thanks for reply, now, after i ignore this error for first, like to receive this again, so "in my own words" to enable this errors again, to catch them, and this is disabled for the rest of my session until i close my application and start them again.

    What handle are you setting the option on? How is m_hRequest obtained? If it's actually a request handle - that is, obtained with WinHttpOpenRequest - then you can only use it once, for a single request. After that request completes, setting options on this request handle is pointless - you can't use it again anyway. The only meaningful thing you can do with it is close it, using WinHttpCloseHandle.

    You need to obtain a new request handle with WinHttpOpenRequest for each request you want to make, and set options on it as needed.

    On the other hand, if you set the option on the session handle (obtained with WinHttpOpen) or connection handle (obtained with WinHttpConnect), then the option would be inherited by every request handle created within that session or connection. Changing the option on the session handle would affect new requests created afterwards, but not request handles that are already created.


    Igor Tandetnik

    Wednesday, May 15, 2013 4:30 PM