Fliwatt Posted October 12, 2018 Posted October 12, 2018 Hello guys, this is my first time working with a web API and trying to navigate that seems really hard, right now I am stuck in how to fetch the JSON results into my script, the website I am using is really simple, it just displays the gender of a name, it is https://api.genderize.io/?name=peter I tried using the WinHTTP function already but it only returns <html> <head><title>400 The plain HTTP request was sent to HTTPS port</title></head> <body bgcolor="white"> <center><h1>400 Bad Request</h1></center> <center>The plain HTTP request was sent to HTTPS port</center> <hr><center>nginx/1.10.3 (Ubuntu)</center> </body> </html> This is my code: #include "WinHttp.au3" Opt("MustDeclareVars", 1) ; Initialize and get session handle Global $hOpen = _WinHttpOpen() ; Get connection handle Global $hConnect = _WinHttpConnect($hOpen, "https://api.genderize.io/?name=peter") ; Request Global $hRequest = _WinHttpSimpleSendRequest($hConnect) ; Simple-read... Global $sRead = _WinHttpSimpleReadData($hRequest) ConsoleWrite( StringLeft($sRead, 1100) & "...") ; Close handles _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) I think I should not retrieve the data using an HTTP call but what should I do instead? Thank you very much for your help!
Danp2 Posted October 12, 2018 Posted October 12, 2018 You're using _WinHttpSimpleSendRequest, which is for HTTP. You'll need to switch to _WinHttpSimpleSendSSLRequest or examine the following simplified example that works -- #include "WinHttp.au3" Opt("MustDeclareVars", 1) ; Initialize and get session handle Global $hOpen = _WinHttpOpen() ; Get connection handle Global $hConnect = _WinHttpConnect($hOpen, "https://api.genderize.io") Local $sReturned = _WinHttpSimpleSSLRequest($hConnect, "GET", "?name=peter") ConsoleWrite( StringLeft($sReturned, 1100) & "...") ; Close handles _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) trancexx 1 Latest Webdriver UDF Release Webdriver Wiki FAQs
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