trancexx Posted February 8, 2019 Author Posted February 8, 2019 On 6.2.2019. at 1:30 PM, HamidZaeri said: Hi @trancexx - How can I receive response Status? (200, 404, 403,...) Should I get it from response Header? - And I have a problem; this request sends to this address: "http://api.server.ir:443/v2/content/" but I want it to be sent to "https://api.server.ir/v2/content/" Global $hOpen = _WinHttpOpen('okhttp/3.10.0');,3,'127.0.0.1:8888') _WinHttpSetOption($hOpen, 118, 0x00000003) $hConnect = _WinHttpConnect($hOpen, "https://api.server.ir") ; Make a request Global $hRequest = _WinHttpOpenRequest($hConnect, "POST", "/v2/content/") _WinHttpAddRequestHeaders($hRequest, "Content-Type: application/x-www-form-urlencoded") _WinHttpSendRequest($hRequest, 'Accept-Encoding: gzip', $rq[$num][0]) _WinHttpReceiveResponse($hRequest) ; Check if there is a response If _WinHttpQueryDataAvailable($hRequest) Then Global $sHeader = _WinHttpQueryHeaders($hRequest), $sReturned MsgBox(64, "Header", $sHeader) Do $sReturned &= _WinHttpReadData($hRequest, 1) Until @error InputBox(1,ClipPut($sReturned),$sReturned) Exit EndIf . Yes, from the response: _WinHttpQueryHeaders($hRequest, $WINHTTP_QUERY_STATUS_CODE) ...I'm not sure what's the question in that second thing. HamidZaeri 1 ♡♡♡ . eMyvnE
HamidZaeri Posted February 18, 2019 Posted February 18, 2019 (edited) On 2/8/2019 at 11:44 PM, trancexx said: Yes, from the response: _WinHttpQueryHeaders($hRequest, $WINHTTP_QUERY_STATUS_CODE) ...I'm not sure what's the question in that second thing. Thanks. Is below code good enough to get status? Or does it need any more condition or any other better code? If @error = 0 Then StringMid($response[0],10,3) ++++ And about this function: "_WinHttpSimpleSSLRequest" What should I edit in "WinHttp" to change header parameter of requests from This: "Accept-Encoding: gzip, deflate" To this: "Accept-Encoding: gzip" Edited February 19, 2019 by HamidZaeri
trancexx Posted February 19, 2019 Author Posted February 19, 2019 On 18.2.2019. at 6:26 PM, HamidZaeri said: Thanks. Is below code good enough to get status? Or does it need any more condition or any other better code? If @error = 0 Then StringMid($response[0],10,3) ++++ And about this function: "_WinHttpSimpleSSLRequest" What should I edit in "WinHttp" to change header parameter of requests from This: "Accept-Encoding: gzip, deflate" To this: "Accept-Encoding: gzip" If it works then it's ok. Status line of HTTP response is standardized. As for the other... why in the world would you want that? HamidZaeri 1 ♡♡♡ . eMyvnE
HamidZaeri Posted February 20, 2019 Posted February 20, 2019 (edited) 16 hours ago, trancexx said: If it works then it's ok. Status line of HTTP response is standardized. As for the other... why in the world would you want that? Cause i need to simulate another request which contains only gzip! BTW thanks for your answers, time and the great udf Edited February 20, 2019 by HamidZaeri
DavidClarke Posted March 7, 2019 Posted March 7, 2019 Hi I am using inHttpWebSocket family of functions. I call WinHttpSetStatusCallback before WinHttpWebSocketCompleteUpgrade but never get SEND and RECEIVE events from WinHttpWebSocketReceive or HttpWebSocketSend. I can't find any documentation for WinHttpSetStatusCallback and how it relates to WinHttpWebSocketReceive or HttpWebSocketSend. Thoughts? Thanks!
moimon Posted March 7, 2019 Posted March 7, 2019 (edited) Sorry, I posted the wrong topic. I hope Mod will help me remove this comment. Thank you. Edited March 7, 2019 by moimon
Flax Posted March 18, 2019 Posted March 18, 2019 Hello, trying to send files with VirusTotal UDF, it uses WinHttp, for some reason, when file ar bigger then 8mb i can't send it, get empty response "0". Small files up to 8mb send fine. Anyone knows why ? VirusTotal accepts files up to 25mb 😕 expandcollapse popupFunc VT(ByRef $aAPI, $Type, $sResource, $sAPIkey,$Comments="") If $aAPI[$eAPI_HttpConnect] = -1 Then $aAPI = VT_Open() Select ;$fReport,$fScan,$fRescan,$uReport,$uScan,$Comment Case $Type = $fReport Return _WinHttpSimpleRequest($aAPI[$eAPI_HttpConnect], 'POST', $tURL[$Type], Default, 'resource=' & $sResource & '&key=' & $sAPIkey) Case $Type = $fScan Local $sBoundary="--------Boundary" Local $sHeaders = "Content-Type: multipart/form-data; boundary=" & $sBoundary & @CRLF Local $sData = '' $sData &= "--" & $sBoundary & @CRLF $sData &= 'Content-Disposition: form-data; name="apikey"' & @CRLF & @CRLF & $sAPIkey & @CRLF $sData &= "--" & $sBoundary & @CRLF $sData &= __WinHttpFileContent("", "file", $sResource,$sBoundary) $sData &= "--" & $sBoundary & "--" & @CRLF Return _WinHttpSimpleRequest($aAPI[$eAPI_HttpConnect], "POST", $tURL[$Type], Default, StringToBinary($sData,0), $sHeaders) Case $Type = $fRescan Return _WinHttpSimpleRequest($aAPI[$eAPI_HttpConnect], "POST", "/vtapi/v2/file/rescan", Default, "resource=" & $sResource &"&key=" & $sAPIkey) Case $Type = $uReport Return _WinHttpSimpleRequest($aAPI[$eAPI_HttpConnect], 'POST', $tURL[$Type], Default, 'resource=' & $sResource & '&key=' & $sAPIkey) Case $Type = $uScan Return _WinHttpSimpleRequest($aAPI[$eAPI_HttpConnect], 'POST', $tURL[$Type], Default, 'url=' & $sResource & '&key=' & $sAPIkey) Case $Type = $Comment return _WinHttpSimpleRequest($aAPI[$eAPI_HttpConnect], "POST", "/vtapi/v2/comments/put", Default, "resource=" & $sResource & _ "&comment=" & $Comments & "&key=" & $sAPIkey) Case Else SetError(3) EndSelect EndFunc ;==>VT
jordin71 Posted March 28, 2019 Posted March 28, 2019 (edited) Hey! I have a problem and i tried A LOT of things but i can't make it work. I will try to explain my self as much as i can. I need to do a http request to a https server, the thing is that i do this : $oHTTP.Open('POST', 'https://www.website.com/page.php', FALSE) ;start connection to website $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") ; header $oHTTP.Send(StringToBinary("var1=1&var2=2&var3=3", 1)) ;sending all the data $sResponse = $oHTTP.ResponseText ;saving the response ConsoleWrite("Response: "&$sResponse&@CRLF) In test it in my main PC(I have a Windows 10) and it worked and still working but when i ran this on another PC(Windows 7(installed yesterday), last Autoit updates) i get a "compatibility error of the secure channel" error by a trap. i dont know if i need to install something that i'm missing or what. So i decide to test your "winhttp.au3" and i do this: $hOpen = _WinHttpOpen() $hConnect = _WinHttpConnect($hOpen, "https://www.website.com") ; Connection handle $sData = "var1=1&var2=2&var3=3" ; The data to send by POST method $sResponse = _WinHttpSimpleSSLRequest($hConnect, "POST", "/page.php", Default, $sData) ; Make the SSL Request _WinHttpCloseHandle($hConnect) ; closing handles _WinHttpCloseHandle($hOpen) ConsoleWrite("Response: "& $sResponse & @CRLF) It looks like it's working but the thing is that the $sResponse return "0" and it shouldn't be returning that, it should be returning a string with 2 numbers. I'm missing something? I need to do something more with $sResponse? it can be my PC mssing a file to do https request correctly? The website is private so I can't make the site public, if i make it public i'm dead and I choose to live Edited March 28, 2019 by jordin71
tczbu Posted March 29, 2019 Posted March 29, 2019 Hi! Please help! I'm trying to send a Pushover notification with an attachment. I grabbed a section of code from an earlier message in this forum, which successfully sends the notification, but I'm unable to get notification to include an attachment. Please advise. Pushover API: https://pushover.net/api#attachments Here is what I grabbed from the earlier post with my failed attempt to add an attachment. #include "WinHttp.au3" $sAddress = "https://api.pushover.net/1/messages.json" $sApiToken = "apitoken" ; <-yours here $sUserKey = "userkey" ; <-yours here $sMessage = "hello world" ; Construct the form Const $sForm = '<form action="' & $sAddress & '" method="post"' & _ '<input name="token" value="' & $sApiToken & '"/>' & _ '<input name="user" value="' & $sUserKey & '"/>' & _ '<input name="message" value="' & $sMessage & '"/>' & _ '<input name="attachment" type="image/jpeg" filename="' & @MyDocumentsDir & "\MyPicture.jpg" & '"/>' & _ '</form>' ; Open session $hOpen = _WinHttpOpen() ; To collect connection handle (because the form is inlined) $hConnect = $sForm ; Fill the form $sRead = _WinHttpSimpleFormFill($hConnect, $hOpen) ; Close handles _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) ; Tada mtfk! MsgBox(4096, "Simon says", $sRead) Thanks!
trancexx Posted March 31, 2019 Author Posted March 31, 2019 On 3/29/2019 at 3:49 PM, tczbu said: Hi! Please help! I'm trying to send a Pushover notification with an attachment. I grabbed a section of code from an earlier message in this forum, which successfully sends the notification, but I'm unable to get notification to include an attachment. Please advise. Pushover API: https://pushover.net/api#attachments Here is what I grabbed from the earlier post with my failed attempt to add an attachment. #include "WinHttp.au3" $sAddress = "https://api.pushover.net/1/messages.json" $sApiToken = "apitoken" ; <-yours here $sUserKey = "userkey" ; <-yours here $sMessage = "hello world" ; Construct the form Const $sForm = '<form action="' & $sAddress & '" method="post"' & _ '<input name="token" value="' & $sApiToken & '"/>' & _ '<input name="user" value="' & $sUserKey & '"/>' & _ '<input name="message" value="' & $sMessage & '"/>' & _ '<input name="attachment" type="image/jpeg" filename="' & @MyDocumentsDir & "\MyPicture.jpg" & '"/>' & _ '</form>' ; Open session $hOpen = _WinHttpOpen() ; To collect connection handle (because the form is inlined) $hConnect = $sForm ; Fill the form $sRead = _WinHttpSimpleFormFill($hConnect, $hOpen) ; Close handles _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) ; Tada mtfk! MsgBox(4096, "Simon says", $sRead) Thanks! It should be: ;... Const $sForm = '<form action="' & $sAddress & '" method="post" enctype="multipart/form-data">' & _ '<input name="token" value="' & $sApiToken & '"/>' & _ '<input name="user" value="' & $sUserKey & '"/>' & _ '<input type="file" name="attachment"/>' & _ '<input name="message" value="' & $sMessage & '"/>' & _ '</form>' ;... $sRead = _WinHttpSimpleFormFill($hConnect, $hOpen, Default, "name:attachment", $sImage) ;... ♡♡♡ . eMyvnE
trancexx Posted March 31, 2019 Author Posted March 31, 2019 On 3/29/2019 at 12:47 AM, jordin71 said: Hey! I have a problem and i tried A LOT of things but i can't make it work. I will try to explain my self as much as i can. I need to do a http request to a https server, the thing is that i do this : $oHTTP.Open('POST', 'https://www.website.com/page.php', FALSE) ;start connection to website $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") ; header $oHTTP.Send(StringToBinary("var1=1&var2=2&var3=3", 1)) ;sending all the data $sResponse = $oHTTP.ResponseText ;saving the response ConsoleWrite("Response: "&$sResponse&@CRLF) In test it in my main PC(I have a Windows 10) and it worked and still working but when i ran this on another PC(Windows 7(installed yesterday), last Autoit updates) i get a "compatibility error of the secure channel" error by a trap. i dont know if i need to install something that i'm missing or what. So i decide to test your "winhttp.au3" and i do this: $hOpen = _WinHttpOpen() $hConnect = _WinHttpConnect($hOpen, "https://www.website.com") ; Connection handle $sData = "var1=1&var2=2&var3=3" ; The data to send by POST method $sResponse = _WinHttpSimpleSSLRequest($hConnect, "POST", "/page.php", Default, $sData) ; Make the SSL Request _WinHttpCloseHandle($hConnect) ; closing handles _WinHttpCloseHandle($hOpen) ConsoleWrite("Response: "& $sResponse & @CRLF) It looks like it's working but the thing is that the $sResponse return "0" and it shouldn't be returning that, it should be returning a string with 2 numbers. I'm missing something? I need to do something more with $sResponse? it can be my PC mssing a file to do https request correctly? The website is private so I can't make the site public, if i make it public i'm dead and I choose to live Try $sResponse = _WinHttpSimpleSSLRequest($hConnect, "POST", "/page.php", Default, $sData, Default, Default, Default, Default, Default, 1) ; Make the SSL Request ♡♡♡ . eMyvnE
jordin71 Posted April 2, 2019 Posted April 2, 2019 (edited) On 3/31/2019 at 10:52 PM, trancexx said: Try $sResponse = _WinHttpSimpleSSLRequest($hConnect, "POST", "/page.php", Default, $sData, Default, Default, Default, Default, Default, 1) ; Make the SSL Request I tried and still getting a return of 0 any other suggestion? If this helps $sResponse returns are these : -$sResponse : 0 -@error : 0 -@extended : 0 Edited April 2, 2019 by jordin71
trancexx Posted April 2, 2019 Author Posted April 2, 2019 8 hours ago, jordin71 said: I tried and still getting a return of 0 any other suggestion? If this helps $sResponse returns are these : -$sResponse : 0 -@error : 0 -@extended : 0 It would be nice to see how you check error number. ♡♡♡ . eMyvnE
tczbu Posted April 4, 2019 Posted April 4, 2019 On 3/31/2019 at 3:39 PM, trancexx said: It should be: ;... Const $sForm = '<form action="' & $sAddress & '" method="post" enctype="multipart/form-data">' & _ '<input name="token" value="' & $sApiToken & '"/>' & _ '<input name="user" value="' & $sUserKey & '"/>' & _ '<input type="file" name="attachment"/>' & _ '<input name="message" value="' & $sMessage & '"/>' & _ '</form>' ;... $sRead = _WinHttpSimpleFormFill($hConnect, $hOpen, Default, "name:attachment", $sImage) ;... That worked! Thank you!!!
joiner Posted April 27, 2019 Posted April 27, 2019 Hello. How to get a page? https://google.com/search?q=smail&tbm=isch&source=lnt&tbs=isz:ex,iszw:500,iszh:500
coffeeturtle Posted May 22, 2019 Posted May 22, 2019 Sometimes when pulling text from a site to display in a msgbox, I get "garbage" characters that I need to replace/remove: $sPull = _WinHttpReadData($hRequest) $sPull = StringRegExpReplace($sPull, "’", "'") $sPull= StringRegExpReplace($sPull, "€", "'") $sPull= StringRegExpReplace($sPull, "â€", "'") $sPull= StringRegExpReplace($sPull, "—", " ") $sPull= StringRegExpReplace($sPull, "Â", "") Is there a way to avoid getting these characters as they don't appear in the text of the websites? Should I be using a different function altogether instead of _WinHttpReadData()? Thank you for your help.
trancexx Posted May 22, 2019 Author Posted May 22, 2019 1 hour ago, coffeeturtle said: Sometimes when pulling text from a site to display in a msgbox, I get "garbage" characters that I need to replace/remove: $sPull = _WinHttpReadData($hRequest) $sPull = StringRegExpReplace($sPull, "’", "'") $sPull= StringRegExpReplace($sPull, "€", "'") $sPull= StringRegExpReplace($sPull, "â€", "'") $sPull= StringRegExpReplace($sPull, "—", " ") $sPull= StringRegExpReplace($sPull, "Â", "") Is there a way to avoid getting these characters as they don't appear in the text of the websites? Should I be using a different function altogether instead of _WinHttpReadData()? Thank you for your help. Try _WinHttpReadData($hRequest, 1) . coffeeturtle 1 ♡♡♡ . eMyvnE
coffeeturtle Posted May 22, 2019 Posted May 22, 2019 1 hour ago, trancexx said: Try _WinHttpReadData($hRequest, 1) . Thank you! Much better! $iMode [optional] Integer representing reading mode. Default is 0 (charset is decoded as it is ANSI). I should have played around with that.
HamidZaeri Posted July 3, 2019 Posted July 3, 2019 (edited) Hi @trancexx I have two questions: 1. How to use winhttp in async mode $hOpen = _WinHttpOpen($brow) _WinHttpSetTimeouts($hOpen, 9900, 60000, 31000, 90000) $hGat = _WinHttpConnect($hOpen, "gateway.neca.com") ;need to start a request but not wait for response _WinHttpSimpleRequest($hGat, "GET", "noise", '', '', Default, True) ; do something ShellExecute($brow[1][1], 'svg.svg') InputBox('Cap:','12') ;and wait here to recieve response Global $re = _winhttpWaitResponse() 2. Is WinHttp capable of working with web-socket? if not is there any other library? Edited July 3, 2019 by HamidZaeri
trancexx Posted July 3, 2019 Author Posted July 3, 2019 (edited) 4 hours ago, HamidZaeri said: Hi @trancexx I have two questions: 1. How to use winhttp in async mode $hOpen = _WinHttpOpen($brow) _WinHttpSetTimeouts($hOpen, 9900, 60000, 31000, 90000) $hGat = _WinHttpConnect($hOpen, "gateway.neca.com") ;need to start a request but not wait for response _WinHttpSimpleRequest($hGat, "GET", "noise", '', '', Default, True) ; do something ShellExecute($brow[1][1], 'svg.svg') InputBox('Cap:','12') ;and wait here to recieve response Global $re = _winhttpWaitResponse() 2. Is WinHttp capable of working with web-socket? if not is there any other library? Look for _WinHttpSimpleReadDataAsync() in the help file that comes with WinHttp.au3 Also read Remarks section for that entry. It explains problems AutoIt internally have. As for the WebSocket, you have examples here on the forum, even in this thread posted by others. But again, AutoIt internally isn't capable of handling it sensibly. Edited July 3, 2019 by trancexx Clarifications HamidZaeri 1 ♡♡♡ . eMyvnE
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