Celtic88 Posted February 12, 2021 Share Posted February 12, 2021 why my code does not work :/ #include "WinHttp.au3" #include "JSON.au3" Opt("MustDeclareVars", 1) Global $hOpen = _WinHttpOpen() Global $hConnect = _WinHttpConnect($hOpen, "https://api.coinpaprika.com/", $INTERNET_DEFAULT_HTTPS_PORT) Global $hRequest = _WinHttpOpenRequest($hConnect, _ "GET", _ "v1/coins/btc-bitcoin") _WinHttpSendRequest($hRequest) _WinHttpReceiveResponse($hRequest) Local $sReturned = '' If _WinHttpQueryDataAvailable($hRequest) Then Do $sReturned &= _WinHttpReadData($hRequest) Until @error EndIf MsgBox(0, 0, $sReturned) Link to comment Share on other sites More sharing options...
Nine Posted February 12, 2021 Share Posted February 12, 2021 Try : #include <InetConstants.au3> Local $sText = BinaryToString(InetRead("https://api.coinpaprika.com/v1/coins/btc-bitcoin", $INET_FORCERELOAD)) ConsoleWrite ($sText & @CRLF) “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Celtic88 Posted February 12, 2021 Author Share Posted February 12, 2021 1 minute ago, Nine said: Try : #include <InetConstants.au3> Local $sText = BinaryToString(InetRead("https://api.coinpaprika.com/v1/coins/btc-bitcoin", $INET_FORCERELOAD)) ConsoleWrite ($sText & @CRLF) Not possible with WinHttp ? Link to comment Share on other sites More sharing options...
Nine Posted February 12, 2021 Share Posted February 12, 2021 Of course, but that is working ? No ? FrancescoDiMuro 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
TheXman Posted February 12, 2021 Share Posted February 12, 2021 (edited) 11 hours ago, Celtic88 said: why my code does not work 😕 @Celtic88 As the error message said, you were trying to send a plain HTTP request over an HTTPS port. So you have two choices to correct the error, you can change the script to send an HTTP request over port 80 or a secure request over port 443. Examples of the 2 options are below: HTTP Request Global $hOpen = _WinHttpOpen() Global $hConnect = _WinHttpConnect($hOpen, "http://api.coinpaprika.com/") Global $hRequest = _WinHttpOpenRequest($hConnect, "GET", "v1/coins/btc-bitcoin") Global $sReturned = '' _WinHttpSendRequest($hRequest) _WinHttpReceiveResponse($hRequest) If _WinHttpQueryDataAvailable($hRequest) Then Do $sReturned &= _WinHttpReadData($hRequest) Until @error EndIf MsgBox(0, 0, $sReturned) OR HTTPS Request Global $hOpen = _WinHttpOpen() Global $hConnect = _WinHttpConnect($hOpen, "https://api.coinpaprika.com/") Global $hRequest = _WinHttpOpenRequest($hConnect, _ "GET", _ "v1/coins/btc-bitcoin", _ "HTTP/1.1", _ $WINHTTP_NO_REFERER, _ "application/json", _ $WINHTTP_FLAG_SECURE _ ) Global $sReturned = '' _WinHttpSendRequest($hRequest) _WinHttpReceiveResponse($hRequest) If _WinHttpQueryDataAvailable($hRequest) Then Do $sReturned &= _WinHttpReadData($hRequest) Until @error EndIf MsgBox(0, 0, $sReturned) For the HTTPS request, note that the _WinHttpOpenRequest function requires the $WINHTTP_FLAG_SECURE parameter for it to send the request using the "secure" HTTPS protocol. Edited February 13, 2021 by TheXman Danyfirex and FrancescoDiMuro 2 CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
Celtic88 Posted February 13, 2021 Author Share Posted February 13, 2021 @TheXman , did you try? Link to comment Share on other sites More sharing options...
Danyfirex Posted February 13, 2021 Share Posted February 13, 2021 @Celtic88 Did you even try @TheXman Example? 🙄 Saludos FrancescoDiMuro and TheXman 2 Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
TheXman Posted February 13, 2021 Share Posted February 13, 2021 (edited) 12 hours ago, Celtic88 said: did you try? Did I try what? Did I try to answer your question as to why your script wasn't working? The answer is yes. Did I show you 2 snippets of code, with context, to further illustrate what I had written in my explanation of your issue? The answer is yes. Did I run my examples to make sure that they worked before posting them? The answer is yes, of course I did. The examples show the relevant parts of you original script, with context, that should be replaced. They are not and were not supposed to be a fully running script. They were snippets of code for you to compare & contrast to your original script in order for you to learn from. I have no idea what you are asking but hopefully I have answered your question. Edited February 13, 2021 by TheXman Danyfirex 1 CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
Nine Posted February 13, 2021 Share Posted February 13, 2021 I believe OP is on Windows 7. I tested it and it doesn't work for me either, but works correctly on Win10. Problem comes from _WinHttpReceiveResponse($hRequest). By check WinAPI_GetLastError, I am receiving error 12175 which means that some protocols are not enabled. For example TLS 1.1/1.2 are disabled by default on Win7. For the moment, I am not pushing further the analysis of this issue. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
TheXman Posted February 13, 2021 Share Posted February 13, 2021 (edited) 14 minutes ago, Nine said: I tested it and it doesn't work for me either Is it safe to assume that by "it" you are referring to the HTTPS script and not the HTTP script? I tested the HTTPS & HTTP scripts on both Windows 7 & 10 and both worked for me. However, I do have TLS 1.1 & 1.2 enabled and working on my Win 7 computers. Edited February 13, 2021 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
Nine Posted February 13, 2021 Share Posted February 13, 2021 Both script are not working for me on Win7. With the same error 12175. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
TheXman Posted February 13, 2021 Share Posted February 13, 2021 (edited) Maybe the COM WinHTTP version may give a bit more error information. It works for me but maybe the OP can run it and see if the console messages provide more info about the specific error. expandcollapse popup#include <Constants.au3> http_get_example() Func http_get_example() Local $oHttp = Null, $oComErr = Null $oComErr = ObjEvent("AutoIt.Error", com_error_handler) If @error Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR", "Unable to register COM error handler - @error = " & @error) $oHttp = ObjCreate("winhttp.winhttprequest.5.1") If @error Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR", "Unable to create HTTP COM object - @error = " & @error) With $oHttp ; Open request, set request header(s), and send request .Open("GET", "https://api.coinpaprika.com/v1/coins/btc-bitcoin") If @error Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR", StringFormat("(0x%X) %s", $oComErr.RetCode, $oComErr.WinDescription)) .SetRequestHeader("Content-Type", "application/json") .Send() If @error Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR", StringFormat("(0x%X) %s", $oComErr.RetCode, $oComErr.Description)) ; If request was not successful, then display error and exit If .Status <> 200 Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR", StringFormat("HTTP Status Code = %s %s", .Status, .StatusText)) ;Display response ConsoleWrite(@CRLF & "HTTP Response:" & @CRLF & .ResponseText) EndWith EndFunc Func com_error_handler($oError) With $oError ConsoleWrite(@ScriptName & " (" & .scriptline & ") : ==> COM Error intercepted !" & @CRLF) ConsoleWrite(@TAB & "Error Number........... " & "0x" & Hex(.number) & @CRLF) ConsoleWrite(@TAB & "Error WinDescription... " & StringStripWS(.windescription, $STR_STRIPTRAILING) & @CRLF) ConsoleWrite(@TAB & "Error Description...... " & StringStripWS(.description , $STR_STRIPTRAILING) & @CRLF) ConsoleWrite(@TAB & "Error ScriptLine....... " & .scriptline & @CRLF) ConsoleWrite(@TAB & "Error RetCode.......... " & "0x" & Hex(.retcode) & @CRLF) EndWith Return ; Return so @error can be trapped by the calling function EndFunc Edited February 19, 2021 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
Danp2 Posted February 13, 2021 Share Posted February 13, 2021 @Nine Are you running the latest winhttp source from github? Note-- there are updates that haven't been officially released so you have to manually grab the latest source. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
TheXman Posted February 13, 2021 Share Posted February 13, 2021 (edited) @Celtic88 If you are getting a similar error when running the COM script, then by following the instructions in the post below, you should be able to resolve the schannel error. I created a new Win 7 SP1 image without the TLS updates and I was able to reproduce the schannel error. RetCode 0x80072F7D = Error 12157 (0x2F7D) ==> COM Error intercepted ! Error Number........... 0x80020009 Error WinDescription... Exception occurred. Error Description...... An error occurred in the secure channel support Error ScriptLine....... 22 Error RetCode.......... 0x80072F7D I applied the windows update and created the associated registry entries and the WinHTTP and COM scripts work on the newly created Win7 VM. The information on how to download the Win7 update and create the registry entries can be found here: The standalone Microsoft Update to add the updated TLS support, in the article, still exists. The Microsoft "Easy Fix" in the article no longer exists on the Microsoft site. I still have a copy of the "Easy Fix" executable if you prefer to have it do the associated registry entries for you instead of manually adding them yourself. Edited February 15, 2021 by TheXman JockoDundee 1 CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
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