Nurav Posted March 18, 2010 Posted March 18, 2010 (edited) Thank you all for your kind educational and informative posts. I am kinda new here, even after searching a lot here and MSDN I am not properly able to ignore the "Certificate ERROR" in WinHTTP function. The URL I am trying to access is "https://208.69.230.55/getHavaIp?hava_name=vgm", if you access from browser it will show certificate error and I have to add exception in Firefox. (IE7 Does not allow me to add exception) The response of the URL is expected to be... <ROOT> − <RETURNSTATUS> <STATUS>1</STATUS> <RESPONSECODE>408</RESPONSECODE> <RESPONSEDETAIL>HAVA is not active</RESPONSEDETAIL> </RETURNSTATUS> </ROOT> Here is that code I wrote... and thank you all for your kind patience and guidance. #include<WinHTTP.au3> ;https://208.69.230.55/getHavaIp?hava_name=vgm $LocalIP = "208.69.230.55" $hw_open = _WinHttpOpen() $hw_connect = _WinHttpConnect($hw_open, $LocalIP) $h_openRequest = _WinHttpOpenRequest($hw_connect, "get", "getHavaIp?") $data = "hava_name=vgm" _WinHttpSendRequest($h_openRequest,$WINHTTP_NO_ADDITIONAL_HEADERS, "",StringLen($data), 0) _WinHttpWriteData($h_openRequest, $data) _WinHttpReceiveResponse($h_openRequest) MsgBox(0, 'Recived', _WinHttpReadData($h_openRequest)) _WinHttpCloseHandle($h_openRequest) _WinHttpCloseHandle($hw_connect) _WinHttpCloseHandle($hw_open) WinHTTP.zip Thank you all... Edited April 5, 2010 by Nurav
trancexx Posted March 18, 2010 Posted March 18, 2010 "https://..." means you have to use $INTERNET_DEFAULT_HTTPS_PORT in _WinHttpConnect(). Also you must specify $WINHTTP_FLAG_SECURE in _WinHttpOpenRequest(). You didn't even connect properly to get "Certificate ERROR" error. ♡♡♡ . eMyvnE
Nurav Posted March 18, 2010 Author Posted March 18, 2010 (edited) I have honestly tried all the permutations and combinations like a stupid without even able to understand this whole http technology! The tip you gave I had tried before, that too didn't help me I am getting "ERROR_INTERNET_OPERATION_CANCELLED" (ERROR CODE = 12017) for _WinHttpReceiveResponse means "The operation was canceled, usually because the handle on which the request was operating was closed before the operation completed." thanks a lot for looking into this. #include<WinHTTP.au3> ;https://208.69.230.55/getHavaIp?hava_name=vgm $LocalIP = "208.69.230.55" $hw_open = _WinHttpOpen() $hw_connect = _WinHttpConnect($hw_open, $LocalIP,$INTERNET_DEFAULT_HTTPS_PORT) $h_openRequest = _WinHttpOpenRequest($hw_connect, "get", "getHavaIp?","","","",$WINHTTP_FLAG_SECURE) $data = "hava_name=vgm" _WinHttpSendRequest($h_openRequest,$WINHTTP_NO_ADDITIONAL_HEADERS, "",StringLen($data), 0) _WinHttpWriteData($h_openRequest, $data) _WinHttpReceiveResponse($h_openRequest) MsgBox(0, 'Recived', _WinHttpReadData($h_openRequest)) _WinHttpCloseHandle($h_openRequest) _WinHttpCloseHandle($hw_connect) _WinHttpCloseHandle($hw_open) Edited April 5, 2010 by Nurav
trancexx Posted March 18, 2010 Posted March 18, 2010 That's certainly more like it. I'm not sure you should be doing _WinHttpWriteData(). Your code lack _WinHttpQueryDataAvailable() function. Find some working example of https somewhere. ♡♡♡ . eMyvnE
Nurav Posted March 18, 2010 Author Posted March 18, 2010 working example of https is available, but none of them explain about ignoring the certificate part...
trancexx Posted March 18, 2010 Posted March 18, 2010 So you have working example but you couldn't even connect properly. Nurav believe me when I say that you didn't come close to the certificate part. Do you understand what I'm saying? ♡♡♡ . eMyvnE
Nurav Posted March 20, 2010 Author Posted March 20, 2010 (edited) Hi Trancexx, I have made some changes with the code... The "GetLastError" for SetOptions returns ERROR 87 (ERROR_INVALID_PARAMETER)(0x57) MSDN Says "GetLastError returns the error ERROR_INVALID_PARAMETER if an option flag is specified that cannot be set." What am I doing wrong here please! ? expandcollapse popup#include<WinHTTP.au3> ;https://208.69.230.55/getHavaIp?hava_name=vgm $LocalIP = "208.69.230.55" $hw_open = _WinHttpOpen() $hw_connect = _WinHttpConnect($hw_open, $LocalIP,443) $h_openRequest = _WinHttpOpenRequest($hw_connect, "get", "getHavaIp?","","","",$WINHTTP_FLAG_SECURE) $data = "hava_name=vgm" _WinHttpSendRequest($h_openRequest,$WINHTTP_NO_ADDITIONAL_HEADERS, "",StringLen($data), 0) $CurrentOption= _WinHttpQueryOption($h_openRequest, $WINHTTP_OPTION_SECURITY_FLAGS) ConsoleWrite("Current option = "&$CurrentOption&" = "&Hex($CurrentOption)&@CRLF) $NewOption=BitOR($CurrentOption, _ $SECURITY_FLAG_IGNORE_UNKNOWN_CA, _ $SECURITY_FLAG_IGNORE_CERT_CN_INVALID, _ $SECURITY_FLAG_IGNORE_CERT_DATE_INVALID) ConsoleWrite("New option = "&$NewOption&" = "&Hex($NewOption)&@CRLF) _WinHttpSetOption($h_openRequest, $WINHTTP_OPTION_SECURITY_FLAGS, $NewOption) $CurrentOption2= _WinHttpQueryOption($h_openRequest, $WINHTTP_OPTION_SECURITY_FLAGS) ConsoleWrite("Resultant option = "&$CurrentOption2&" = "&Hex($CurrentOption2)&@CRLF) _WinHttpWriteData($h_openRequest, $data) _WinHttpReceiveResponse($h_openRequest) MsgBox(0, 'Recived', _WinHttpReadData($h_openRequest)) _WinHttpCloseHandle($h_openRequest) _WinHttpCloseHandle($hw_connect) _WinHttpCloseHandle($hw_open) Edited April 5, 2010 by Nurav
ProgAndy Posted March 20, 2010 Posted March 20, 2010 (edited) You must set the options before sending the request. Maybe you have to set the options for $hw_connect or $hw_open instead of $h_openRequest, too. Edited March 20, 2010 by ProgAndy *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes
Nurav Posted March 20, 2010 Author Posted March 20, 2010 No that didnt help. The QueryOptions then returned 0
Nurav Posted March 24, 2010 Author Posted March 24, 2010 (edited) Someone please..... Please help ! Edited March 25, 2010 by Nurav
Nurav Posted April 4, 2010 Author Posted April 4, 2010 When the gods of Autoit dragged me here and there with a carrot in front I got tired and it did not help me too much. It was quite challenging me for to find a solution. (My never give up attitude) But sometimes it really does not matter how you do it but what matters is did you do it or not. (It is not the way but the destination which really matters. ) I still dont know how to solve this using winhttp.au3 or directly calling the winhttp dll. One of my kind friend resolved this for me after calling winhttp as a com object. (he also gave up the winhttp.au3 after spending 4 days on it.) winhttp - Ignorance is bliss for me! Too much of story, but I thank all of you who helped, who tried to help, who acted like helping and helpless spectators. -Nurav
ProgAndy Posted April 5, 2010 Posted April 5, 2010 (edited) I looked again at WinHTTP and found an error in _WinHTTPSetOption. It was only designed for String-options. Here is a corrected version: expandcollapse popup#include<WinHTTP.au3> ;https://208.69.230.50/getHavaIp?hava_name=vgm $LocalIP = "208.69.230.50" $hw_open = _WinHttpOpen() $hw_connect = _WinHttpConnect($hw_open, $LocalIP,$INTERNET_DEFAULT_HTTPS_PORT) $h_openRequest = _WinHttpOpenRequest($hw_connect, "get", "getHavaIp?hava_name=vgm","","","",$WINHTTP_FLAG_SECURE) $data = "hava_name=vgm" $allow_unknownCA_wrongCN = BitOR($SECURITY_FLAG_IGNORE_UNKNOWN_CA, $SECURITY_FLAG_IGNORE_CERT_CN_INVALID) $r = _WinHttpSetOptionEx($h_openRequest, $WINHTTP_OPTION_SECURITY_FLAGS, $allow_unknownCA_wrongCN) MsgBox(0, '', $r) _WinHttpSendRequest($h_openRequest) ; send request _WinHttpReceiveResponse($h_openRequest) ; wait for response $sHeaders = _WinHttpQueryHeaders($h_openRequest) $sData = "" If _WinHTTPQueryDataAvailable($h_openRequest) Then Do $sData &= _WinHttpReadData($h_openRequest) Until @error<>0 EndIf _WinHttpCloseHandle($h_openRequest) _WinHttpCloseHandle($hw_connect) _WinHttpCloseHandle($hw_open) MsgBox(0, 'Header', $sHeaders) MsgBox(0, 'Data', $sData) ; #FUNCTION# ;=============================================================================== ; ; Name...........: _WinHttpSetOptionEx ; Description ...: Sets an Internet option. ; Syntax.........: _WinHttpSetOption($hInternet, $iOption, $sSetting) ; Parameters ....: $hInternet - Handle on which to set data. ; $iOption - Integer value that contains the Internet option to set. ; $vSetting - Value of setting ; $iSize - [optional] Size of $vSetting, required if $vSetting is pointer to memory block ; Return values .: Success - Returns 1. ; Failure - Returns 0 and sets @error: ; |1 - DllCall failed. ; Author ........: trancexx, ProgAndy ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........; http://msdn.microsoft.com/en-us/library/aa384114(VS.85).aspx ; Example .......; Yes ; ;========================================================================================== Func _WinHttpSetOptionEx($hInternet, $iOption, $vSetting, $iSize=-1) If IsBinary($vSetting) Then $iSize = DllStructCreate("byte[" & BinaryLen($vSetting) & "]") DllStructSetData($iSize, 1, $vSetting) $vSetting = $iSize $iSize = DllStructGetSize($vSetting) EndIf Local $sType = __WinHTTPGetOptionType($iOption, $iSize) If $iSize < 1 Then If $sType = "wstr" Then $iSize = StringLen($sType) ElseIf IsDllStruct($vSetting) Then $iSize = DllStructGetSize($vSetting) Else Return SetError(2,0,0) EndIf EndIf If IsDllStruct($vSetting) Then Local $a_iCall = DllCall("winhttp.dll", "int", "WinHttpSetOption", "handle", $hInternet, "dword", $iOption, $sType, DllStructGetPtr($vSetting), "dword", $iSize) Else Local $a_iCall = DllCall("winhttp.dll", "int", "WinHttpSetOption", "handle", $hInternet, "dword", $iOption, $sType, $vSetting, "dword", $iSize) EndIf If @error Or Not $a_iCall[0] Then Return SetError(1, 0, 0) Return SetError(0, 0, 1) EndFunc ;==>_WinHttpSetOptionEx Func __WinHTTPGetOptionType($iOption, ByRef $iSize) ; Author: ProgAndy Switch $iOption Case $WINHTTP_OPTION_AUTOLOGON_POLICY, $WINHTTP_OPTION_CODEPAGE, $WINHTTP_OPTION_CONFIGURE_PASSPORT_AUTH, $WINHTTP_OPTION_CONNECT_RETRIES, _ $WINHTTP_OPTION_CONNECT_TIMEOUT, $WINHTTP_OPTION_DISABLE_FEATURE, $WINHTTP_OPTION_ENABLE_FEATURE, $WINHTTP_OPTION_ENABLETRACING, _ $WINHTTP_OPTION_EXTENDED_ERROR, $WINHTTP_OPTION_HANDLE_TYPE, _ $WINHTTP_OPTION_MAX_CONNS_PER_1_0_SERVER, $WINHTTP_OPTION_MAX_CONNS_PER_SERVER, $WINHTTP_OPTION_MAX_HTTP_AUTOMATIC_REDIRECTS, _ $WINHTTP_OPTION_MAX_HTTP_STATUS_CONTINUE, $WINHTTP_OPTION_MAX_RESPONSE_DRAIN_SIZE, $WINHTTP_OPTION_MAX_RESPONSE_HEADER_SIZE, _ $WINHTTP_OPTION_READ_BUFFER_SIZE, $WINHTTP_OPTION_RECEIVE_TIMEOUT, _ $WINHTTP_OPTION_RECEIVE_RESPONSE_TIMEOUT, $WINHTTP_OPTION_REDIRECT_POLICY, $WINHTTP_OPTION_REJECT_USERPWD_IN_URL, _ $WINHTTP_OPTION_REQUEST_PRIORITY, $WINHTTP_OPTION_RESOLVE_TIMEOUT, $WINHTTP_OPTION_SECURE_PROTOCOLS, $WINHTTP_OPTION_SECURITY_FLAGS, _ $WINHTTP_OPTION_SECURITY_KEY_BITNESS, $WINHTTP_OPTION_SEND_TIMEOUT, $WINHTTP_OPTION_SPN, $WINHTTP_OPTION_USE_GLOBAL_SERVER_CREDENTIALS, _ $WINHTTP_OPTION_WORKER_THREAD_COUNT, $WINHTTP_OPTION_WRITE_BUFFER_SIZE $sType = "DWORD*" $iSize = 4 Case $WINHTTP_OPTION_CALLBACK, $WINHTTP_OPTION_PARENT_HANDLE, $WINHTTP_OPTION_PASSPORT_RETURN_URL, $WINHTTP_OPTION_PASSPORT_SIGN_OUT, _ $WINHTTP_OPTION_CLIENT_CERT_ISSUER_LIST $sType = "ptr*" $iSize = 4 If @AutoItX64 Then $iSize = 8 Case $WINHTTP_OPTION_CONTEXT_VALUE $sType = "dword_ptr*" $iSize = 4 If @AutoItX64 Then $iSize = 8 Case $WINHTTP_OPTION_PASSPORT_COBRANDING_TEXT, $WINHTTP_OPTION_PASSPORT_COBRANDING_URL, $WINHTTP_OPTION_PASSWORD, $WINHTTP_OPTION_PROXY_PASSWORD, _ $WINHTTP_OPTION_PROXY_USERNAME, $WINHTTP_OPTION_URL, $WINHTTP_OPTION_USER_AGENT, _ $WINHTTP_OPTION_USERNAME $sType = "wstr" Case Else $sType = "ptr" EndSwitch Return $sType EndFunc Edited April 5, 2010 by ProgAndy *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes
Nurav Posted April 5, 2010 Author Posted April 5, 2010 (edited) Thank you ProgAndy... I am sure the change you made will be helpful for others who are facing similar problems. And of course it works beautifully. Thanks again for "REALLY" looking into the problem and the attitude to "HELP" others. Regards, -Nurav Edited April 5, 2010 by Nurav
Dreamfire Posted September 7, 2010 Posted September 7, 2010 I looked again at WinHTTP and found an error in _WinHTTPSetOption. It was only designed for String-options.Thanks ProgAndy, your method solved my issue also > http://www.autoitscript.com/forum/index.php?showtopic=116139
ProgAndy Posted September 7, 2010 Posted September 7, 2010 _WinHTTPSetOption should be fixed in the new WinHTTP-release (1.6.1.7). *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now