lionfaggot Posted February 9, 2014 Share Posted February 9, 2014 expandcollapse popup$oHTTP = ObjCreate("winhttp.winhttprequest.5.1") Func _Get($host, $page, $referrer = 0, $headret = 0) $hostpage = "http://" & $host & $page ;MsgBox(0,"",$host) $gcookie = _getcookie($host) $oHTTP.Open("GET", $hostpage, False) $oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:27.0) Gecko/20100101 Firefox/27.0") If $referrer <> 0 Then $oHTTP.SetRequestHeader("Referer", $referrer) EndIf If $gcookie <> -1 Then $cookm = StringReplace($gcookie, "Cookie: ", "") $oHTTP.SetRequestHeader("Cookie", $cookm) EndIf $oHTTP.Send() $HeaderResponses = $oHTTP.GetAllResponseHeaders() _cookie($host, $HeaderResponses) If $headret = 0 Then Return $oHTTP.ResponseText Else Return $HeaderResponses EndIf EndFunc ;==>_Get Func _Post($host, $page, $pdat, $referrer = 0, $headret = 0) $hostpage = "http://" & $host & $page ;MsgBox(0,"",$host) $gcookie = _getcookie($host) $oHTTP.Open("POST", $hostpage, True) $oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:27.0) Gecko/20100101 Firefox/27.0") If $referrer <> 0 Then $oHTTP.SetRequestHeader("Referer", $referrer) EndIf $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") If $gcookie <> -1 Then $cookm = StringReplace($gcookie, "Cookie: ", "") $oHTTP.SetRequestHeader("Cookie", $cookm) EndIf $oHTTP.Send($pdat) $HeaderResponses = $oHTTP.GetAllResponseHeaders() _cookie($host, $HeaderResponses) If $headret = 0 Then Return $oHTTP.ResponseText Else Return $HeaderResponses EndIf EndFunc ;==>_Post Func _cookie($host, $retcook) DirCreate(@UserProfileDir & "\" & $host & "\") $array = StringRegExp($retcook, "Set-Cookie: (.+)\r\n", 3) $cookies = "" For $i = 0 To UBound($array) - 1 $cookies = $array[$i] & ";" $csplit = StringSplit($cookies, "=") $cookname = $csplit[1] $cookies = StringRegExpReplace($cookies, "( path| domain| expires)=[^;]+", "") $cookies = StringRegExpReplace($cookies, " HttpOnly", "") $cookies = StringRegExpReplace($cookies, "[;]{2,}", ";") DirCreate(@UserProfileDir & "\" & $host & "\") FileDelete(@UserProfileDir & "\" & $host & "\" & $cookname & ".txt") FileWrite(@UserProfileDir & "\" & $host & "\" & $cookname & ".txt", $cookies) Next EndFunc ;==>_cookie Func _getcookie($host) Local $noret = 0 $cookrr = "Cookie:" $search = FileFindFirstFile(@UserProfileDir & "\" & $host & "\*.txt") If @error Then Return -1 $noret = 1 EndIf If $noret <> 1 Then While 1 $file = FileFindNextFile($search) If @error Then Return $cookrr ExitLoop Else $cookrr &= " " & FileRead(@UserProfileDir & "\" & $host & "\" & $file) EndIf WEnd EndIf $noret = 0 EndFunc ;==>_getcookie Func _URLEncode($toEncode, $encodeType = 0) Local $strHex = "", $iDec Local $aryChar = StringSplit($toEncode, "") If $encodeType = 1 Then;;Encode EVERYTHING For $i = 1 To $aryChar[0] $strHex = $strHex & "%" & Hex(Asc($aryChar[$i]), 2) Next Return $strHex ElseIf $encodeType = 0 Then;;Practical Encoding For $i = 1 To $aryChar[0] $iDec = Asc($aryChar[$i]) If $iDec <= 32 Or $iDec = 37 Then $strHex = $strHex & "%" & Hex($iDec, 2) Else $strHex = $strHex & $aryChar[$i] EndIf Next Return $strHex ElseIf $encodeType = 2 Then;;RFC 1738 Encoding For $i = 1 To $aryChar[0] If Not StringInStr("$-_.+!*'(),;/?:@=&abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", $aryChar[$i]) Then $strHex = $strHex & "%" & Hex(Asc($aryChar[$i]), 2) Else $strHex = $strHex & $aryChar[$i] EndIf Next Return $strHex EndIf EndFunc ;==>_URLEncode everything works fine but i do not think it is sending the cookie with the request, and no, i do not want to use winhttp.au3. the functions surrounding that udf annoy me Link to comment Share on other sites More sharing options...
lionfaggot Posted February 9, 2014 Author Share Posted February 9, 2014 bump Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 9, 2014 Moderators Share Posted February 9, 2014 lionfaggot,Please do not bump your own threads within 24 hours. Remember that this is not a 24/7 support forum - those who answer are only here because they like helping others and have some time to spare. Although the problem might be urgent to you, it is not to anyone else. You just have to wait until someone who knows something about your particular problem, and is willing to help, comes online. Be patient and someone will answer eventually. M23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
lionfaggot Posted February 9, 2014 Author Share Posted February 9, 2014 (edited) i think winhttp is just broken, i got this example from other people. this is in the msdn documentation. im about to ditch windows iif i cant get this working, like straight up. same set of events more ore less in perl on linux with curl works 100% with no frills. and yes i know you can use curl on windows, but it does not come with windows so its not optimal Edited February 9, 2014 by lionfaggot Link to comment Share on other sites More sharing options...
lionfaggot Posted February 19, 2014 Author Share Posted February 19, 2014 so uh, its been days so im gonna bump this again. surely someone knows why winhttp just refuses to handle cookies Link to comment Share on other sites More sharing options...
ripdad Posted February 20, 2014 Share Posted February 20, 2014 (edited) I'm pretty sure WinHTTP handles cookies -- it's just a matter of finding out what it expects for a particular request. I used your script in the OP, and set a request with a cookie, and the server returned with the Same cookie. So, That seems to be working okay. I'm not sure what it is you're trying to do -- or where/what point it is failing. If you could be a bit more specific with details... . Edited February 20, 2014 by ripdad "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward Link to comment Share on other sites More sharing options...
lionfaggot Posted February 21, 2014 Author Share Posted February 21, 2014 I'm pretty sure WinHTTP handles cookies -- it's just a matter of finding out what it expects for a particular request. I used your script in the OP, and set a request with a cookie, and the server returned with the Same cookie. So, That seems to be working okay. I'm not sure what it is you're trying to do -- or where/what point it is failing. If you could be a bit more specific with details... . yes, the cookie sets to file, but does not carry over in the request. if winhttp autohandles cookies then why am i having such a hard time carrying through with those provisions? i have no problems setting the cookie, the issue im having deals with using the set cookie Link to comment Share on other sites More sharing options...
ripdad Posted February 21, 2014 Share Posted February 21, 2014 In that case, WinHTTP does not "autohandle" cookies. You have to code that part yourself. Just keep using the same cookie, until you're done with it. If you get stuck - come back with a snippet and we'll try to figure it out. "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward Link to comment Share on other sites More sharing options...
lionfaggot Posted February 21, 2014 Author Share Posted February 21, 2014 In that case, WinHTTP does not "autohandle" cookies. You have to code that part yourself. Just keep using the same cookie, until you're done with it. If you get stuck - come back with a snippet and we'll try to figure it out. ok, great and all, but why is the request not using the cookie i specify? i can specify any value and it will not set the supplied cookie. Link to comment Share on other sites More sharing options...
ripdad Posted February 22, 2014 Share Posted February 22, 2014 I have not tried anything with "cookie handling" and WinHTTP, but I would suppose the first step is to save the cookie to a Global variable, once you have it, then call a specific function that does what you expect. One thing about WinHTTP, you can only call each WinHTTP function one at a time with Send. So, you might have to call one or more functions to get what you want. I'm still not clear on what you're trying to achieve. "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward Link to comment Share on other sites More sharing options...
lionfaggot Posted February 22, 2014 Author Share Posted February 22, 2014 I have not tried anything with "cookie handling" and WinHTTP, but I would suppose the first step is to save the cookie to a Global variable, once you have it, then call a specific function that does what you expect. One thing about WinHTTP, you can only call each WinHTTP function one at a time with Send. So, you might have to call one or more functions to get what you want. I'm still not clear on what you're trying to achieve. ok dude, as you can PLAINLY SEE, my function has no issues recording the cookie. but it wont USE the cookies. which makes no sense at all, like literally its fairy unicorn logic, and the reason no one can help me is because i can p much guarantee no one has gotten this to function, ever. not even once Link to comment Share on other sites More sharing options...
ripdad Posted February 23, 2014 Share Posted February 23, 2014 I don't mind a merry-go-round two or three times. After that, I get dizzy. You haven't provided enough information to latch onto. Good luck to you! "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward 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