jackchen Posted June 25, 2015 Posted June 25, 2015 Ah yes, option to list all was added with win8. On your system it's not possible to list all entries using underlying function. Did you search around the web to see how to do it on pre-win8 systems?I found this topic https://groups.google.com/forum/#!topic/microsoft.public.security.crypto/WHwxS2vG_0E point out the way:Subject Alternative Names (SAN) are certificate extensions. Programmatically you can get to them by accessing rgExtension member of the pCertInfo(CERT_INFO) member of the CERT_CONTEXT structure. Use CertFindExtension() to find an extension by oid = szOID_SUBJECT_ALT_NAME2. To format the encoded string into WCHAR string use CryptFormatObject().And this: http://swift.im/git/swift/plain/Swiften/TLS/Schannel/SchannelCertificate.cpp , some c codes to parse SSL certificate,but I have no knowledge of c language,it puzzles me.
trancexx Posted June 25, 2015 Author Posted June 25, 2015 ^^In that case it's not that hard to do it. Try this:expandcollapse popup#include "WinHttp.au3" $hOpen = _WinHttpOpen() $hConnect = _WinHttpConnect($hOpen, "https://www.facebook.com") $hRequest = _WinHttpSimpleSendSSLRequest($hConnect) ; Query for CERT_CONTEXT pointer $tBuffer = DllStructCreate("ptr") DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpQueryOption", _ "handle", $hRequest, _ "dword", $WINHTTP_OPTION_SERVER_CERT_CONTEXT, _ "struct*", $tBuffer, _ "dword*", DllStructGetSize($tBuffer)) Local $pCertContext = DllStructGetData($tBuffer, 1) ; Close handles _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) ConsoleWrite("> CERT_CONTEXT pointer: " & $pCertContext & @CRLF) Local $tCERT_CONTEXT = DllStructCreate("dword dwCertEncodingType;" & _ "ptr pbCertEncoded;" & _ "dword cbCertEncoded;" & _ "ptr pCertInfo;" & _ "handle hCertStore", _ $pCertContext) $pCERT_INFO = $tCERT_CONTEXT.pCertInfo ConsoleWrite("> $pCERT_INFO pointer: " & $pCERT_INFO & @CRLF) ; CERT_INFO struct is complex one made out of number of others. Reinterpret $pCERT_INFO as CERT_INFO struct pointer $tCERT_INFO = DllStructCreate( _ "struct;" & _ "dword dwVersion;" & _ "struct;" & _ ; SerialNumber CRYPT_INTEGER_BLOB "dword SerialNumber_cbData;" & _ "ptr SerialNumber_pbData;" & _ "endstruct;" & _ "struct;" & _ ; SignatureAlgorithm CRYPT_ALGORITHM_IDENTIFIER "ptr SignatureAlgorithm_pszObjId;" & _ "struct;" & _ ; SignatureAlgorithm.Parameters CRYPT_OBJID_BLOB "dword SignatureAlgorithm_Parameters_cbData;" & _ "ptr SignatureAlgorithm_Parameters_pbData;" & _ "endstruct;" & _ "endstruct;" & _ "struct;" & _ ; Issuer CERT_NAME_BLOB "dword Issuer_cbData;" & _ "ptr Issuer_pbData;" & _ "endstruct;" & _ "struct;" & _ ; NotBefore FILETIME "dword NotBefore_dwLowDateTime;" & _ "dword NotBefore_dwHighDateTime;" & _ "endstruct;" & _ "struct;" & _ ; NotAfter FILETIME "dword NotAfter_dwLowDateTime;" & _ "dword NotAfter_dwHighDateTime;" & _ "endstruct;" & _ "struct;" & _ ; Subject CERT_NAME_BLOB "dword Subject_cbData;" & _ "ptr Subject_pbData;" & _ "endstruct;" & _ "struct;" & _ ; SubjectPublicKeyInfo CERT_PUBLIC_KEY_INFO "struct;" & _ ; SubjectPublicKeyInfo.Algorithm CRYPT_ALGORITHM_IDENTIFIER "ptr SubjectPublicKeyInfo_Algorithm_pszObjId;" & _ "struct;" & _ ; SubjectPublicKeyInfo.Parameters CRYPT_OBJID_BLOB "dword SubjectPublicKeyInfo_Parameters_cbData;" & _ "ptr SubjectPublicKeyInfo_Parameters_pbData;" & _ "endstruct;" & _ "endstruct;" & _ "struct;" & _ ; SubjectPublicKeyInfo.PublicKey CRYPT_BIT_BLOB "dword SubjectPublicKeyInfo_PublicKey_cbData;" & _ "ptr ParametersSubjectPublicKeyInfo_pbData;" & _ "dword SubjectPublicKeyInfo_PublicKey_cUnusedBits;" & _ "endstruct;" & _ "endstruct;" & _ "struct;" & _ ; IssuerUniqueId CRYPT_BIT_BLOB "dword IssuerUniqueId_cbData;" & _ "ptr IssuerUniqueId_pbData;" & _ "dword IssuerUniqueId_cUnusedBits;" & _ "endstruct;" & _ "struct;" & _ ; SubjectUniqueId CRYPT_BIT_BLOB "dword dwSubjectUniqueId_cbData;" & _ "ptr SubjectUniqueId_pbData;" & _ "dword SubjectUniqueId_cUnusedBits;" & _ "endstruct;" & _ "dword cExtension;" & _ "ptr rgExtension;" & _ "endstruct;" , _ $pCERT_INFO) ; Read wanted data out of it $iExtensions = $tCERT_INFO.cExtension $pExtensions = $tCERT_INFO.rgExtension ConsoleWrite("> $pExtensions pointer = " & $pExtensions & @CRLF) ; Find subject alternative name extension Const $szOID_SUBJECT_ALT_NAME2 = "2.5.29.17" $aCall = DllCall("Crypt32.dll", "ptr", "CertFindExtension", _ "str", $szOID_SUBJECT_ALT_NAME2, _ "dword", $iExtensions, _ "ptr", $pExtensions) $pExtension = $aCall[0] ; here it is! ConsoleWrite("!> $pExtension pointer = " & $pExtension & @CRLF) Const $X509_ASN_ENCODING = 0x00000001 Const $CRYPT_FORMAT_STR_MULTI_LINE = 0x0001 $tCERT_EXTENSION = DllStructCreate( _ "struct;" & _ "ptr pszObjId;" & _ "bool fCritical;" & _ "struct;" & _ ; Value CRYPT_OBJID_BLOB "dword Value_cbData;" & _ "ptr Value_pbData;" & _ "endstruct;" & _ "endstruct;", _ $pExtension) $aCall = DllCall("Crypt32.dll", "int", "CryptFormatObject", _ "dword", $X509_ASN_ENCODING, _ "dword", 0, _ "dword", $CRYPT_FORMAT_STR_MULTI_LINE, _ "ptr", 0, _ "ptr", $tCERT_EXTENSION.pszObjId, _ "ptr", $tCERT_EXTENSION.Value_pbData, _ "dword", $tCERT_EXTENSION.Value_cbData, _ "wstr", "", _ "dword*",65536) ConsoleWrite("Subject Alternative Name" & @CRLF & $aCall[8] & @CRLF) ; Free CERT_CONTEXT DllCall("Crypt32.dll", "dword", "CertFreeCertificateContext", "ptr", $pCertContext)...Say thanks to that guy from first link. ♡♡♡ . eMyvnE
water Posted June 25, 2015 Posted June 25, 2015 And don't forget to say thanks to trancexx too My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
jackchen Posted June 26, 2015 Posted June 26, 2015 ^^In that case it's not that hard to do it. Try this:expandcollapse popup#include "WinHttp.au3" $hOpen = _WinHttpOpen() $hConnect = _WinHttpConnect($hOpen, "https://www.facebook.com") $hRequest = _WinHttpSimpleSendSSLRequest($hConnect) ; Query for CERT_CONTEXT pointer $tBuffer = DllStructCreate("ptr") DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpQueryOption", _ "handle", $hRequest, _ "dword", $WINHTTP_OPTION_SERVER_CERT_CONTEXT, _ "struct*", $tBuffer, _ "dword*", DllStructGetSize($tBuffer)) Local $pCertContext = DllStructGetData($tBuffer, 1) ; Close handles _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) ConsoleWrite("> CERT_CONTEXT pointer: " & $pCertContext & @CRLF) Local $tCERT_CONTEXT = DllStructCreate("dword dwCertEncodingType;" & _ "ptr pbCertEncoded;" & _ "dword cbCertEncoded;" & _ "ptr pCertInfo;" & _ "handle hCertStore", _ $pCertContext) $pCERT_INFO = $tCERT_CONTEXT.pCertInfo ConsoleWrite("> $pCERT_INFO pointer: " & $pCERT_INFO & @CRLF) ; CERT_INFO struct is complex one made out of number of others. Reinterpret $pCERT_INFO as CERT_INFO struct pointer $tCERT_INFO = DllStructCreate( _ "struct;" & _ "dword dwVersion;" & _ "struct;" & _ ; SerialNumber CRYPT_INTEGER_BLOB "dword SerialNumber_cbData;" & _ "ptr SerialNumber_pbData;" & _ "endstruct;" & _ "struct;" & _ ; SignatureAlgorithm CRYPT_ALGORITHM_IDENTIFIER "ptr SignatureAlgorithm_pszObjId;" & _ "struct;" & _ ; SignatureAlgorithm.Parameters CRYPT_OBJID_BLOB "dword SignatureAlgorithm_Parameters_cbData;" & _ "ptr SignatureAlgorithm_Parameters_pbData;" & _ "endstruct;" & _ "endstruct;" & _ "struct;" & _ ; Issuer CERT_NAME_BLOB "dword Issuer_cbData;" & _ "ptr Issuer_pbData;" & _ "endstruct;" & _ "struct;" & _ ; NotBefore FILETIME "dword NotBefore_dwLowDateTime;" & _ "dword NotBefore_dwHighDateTime;" & _ "endstruct;" & _ "struct;" & _ ; NotAfter FILETIME "dword NotAfter_dwLowDateTime;" & _ "dword NotAfter_dwHighDateTime;" & _ "endstruct;" & _ "struct;" & _ ; Subject CERT_NAME_BLOB "dword Subject_cbData;" & _ "ptr Subject_pbData;" & _ "endstruct;" & _ "struct;" & _ ; SubjectPublicKeyInfo CERT_PUBLIC_KEY_INFO "struct;" & _ ; SubjectPublicKeyInfo.Algorithm CRYPT_ALGORITHM_IDENTIFIER "ptr SubjectPublicKeyInfo_Algorithm_pszObjId;" & _ "struct;" & _ ; SubjectPublicKeyInfo.Parameters CRYPT_OBJID_BLOB "dword SubjectPublicKeyInfo_Parameters_cbData;" & _ "ptr SubjectPublicKeyInfo_Parameters_pbData;" & _ "endstruct;" & _ "endstruct;" & _ "struct;" & _ ; SubjectPublicKeyInfo.PublicKey CRYPT_BIT_BLOB "dword SubjectPublicKeyInfo_PublicKey_cbData;" & _ "ptr ParametersSubjectPublicKeyInfo_pbData;" & _ "dword SubjectPublicKeyInfo_PublicKey_cUnusedBits;" & _ "endstruct;" & _ "endstruct;" & _ "struct;" & _ ; IssuerUniqueId CRYPT_BIT_BLOB "dword IssuerUniqueId_cbData;" & _ "ptr IssuerUniqueId_pbData;" & _ "dword IssuerUniqueId_cUnusedBits;" & _ "endstruct;" & _ "struct;" & _ ; SubjectUniqueId CRYPT_BIT_BLOB "dword dwSubjectUniqueId_cbData;" & _ "ptr SubjectUniqueId_pbData;" & _ "dword SubjectUniqueId_cUnusedBits;" & _ "endstruct;" & _ "dword cExtension;" & _ "ptr rgExtension;" & _ "endstruct;" , _ $pCERT_INFO) ; Read wanted data out of it $iExtensions = $tCERT_INFO.cExtension $pExtensions = $tCERT_INFO.rgExtension ConsoleWrite("> $pExtensions pointer = " & $pExtensions & @CRLF) ; Find subject alternative name extension Const $szOID_SUBJECT_ALT_NAME2 = "2.5.29.17" $aCall = DllCall("Crypt32.dll", "ptr", "CertFindExtension", _ "str", $szOID_SUBJECT_ALT_NAME2, _ "dword", $iExtensions, _ "ptr", $pExtensions) $pExtension = $aCall[0] ; here it is! ConsoleWrite("!> $pExtension pointer = " & $pExtension & @CRLF) Const $X509_ASN_ENCODING = 0x00000001 Const $CRYPT_FORMAT_STR_MULTI_LINE = 0x0001 $tCERT_EXTENSION = DllStructCreate( _ "struct;" & _ "ptr pszObjId;" & _ "bool fCritical;" & _ "struct;" & _ ; Value CRYPT_OBJID_BLOB "dword Value_cbData;" & _ "ptr Value_pbData;" & _ "endstruct;" & _ "endstruct;", _ $pExtension) $aCall = DllCall("Crypt32.dll", "int", "CryptFormatObject", _ "dword", $X509_ASN_ENCODING, _ "dword", 0, _ "dword", $CRYPT_FORMAT_STR_MULTI_LINE, _ "ptr", 0, _ "ptr", $tCERT_EXTENSION.pszObjId, _ "ptr", $tCERT_EXTENSION.Value_pbData, _ "dword", $tCERT_EXTENSION.Value_cbData, _ "wstr", "", _ "dword*",65536) ConsoleWrite("Subject Alternative Name" & @CRLF & $aCall[8] & @CRLF) ; Free CERT_CONTEXT DllCall("Crypt32.dll", "dword", "CertFreeCertificateContext", "ptr", $pCertContext)...Say thanks to that guy from first link.trancexx,perfect!Tons of thanks to you,you are our hero
jaberwacky Posted July 20, 2015 Posted July 20, 2015 (edited) So I'm trying to make a script to upload images to Imgur. I'd like to use the latest version of the API because that's all I can get keys for. I found the following VB code: http://pc-tips.net/imgur-api-vb-net/ which I have converted as much as possible to AutoIt:expandcollapse popupUploadImage(FileOpenDialog("Open", @ScriptDir, "Images (*.jpg;*.gif;*.png;*.bmp)", $FD_FILEMUSTEXIST)) Func UploadImage($image) ; I assume WinHttp can be used in place of the following? Local $w As WebClient() $w.Headers.Add("Authorization", "Client-ID Put your client id here") Local $base64_image = _Base64Encode($image) Local $responseArray = $w.UploadValues("https://api.imgur.com/3/image", $base64_image) ; I'll look into the regex matching when I can see the actual response Local $result = Encoding.ASCII.GetString($responseArray) Local $reg = System.Text.RegularExpressions.Regex("link"":""(.*?)""") Local $match = $reg.Match($result) Local $url = $match.ToString.Replace("link"":""", "").Replace("""", "").Replace("\/", "/") Return $url EndFunc ; Author: Ward Func _Base64Encode($Data, $LineBreak = 76) Local $Opcode = "0x5589E5FF7514535657E8410000004142434445464748494A4B4C4D4E4F505152535455565758595A6162636465666768696A6B6C6D6E6F707172737475767778797A303132333435363738392B2F005A8B5D088B7D108B4D0CE98F0000000FB633C1EE0201D68A06880731C083F901760C0FB6430125F0000000C1E8040FB63383E603C1E60409C601D68A0688470183F90176210FB6430225C0000000C1E8060FB6730183E60FC1E60209C601D68A06884702EB04C647023D83F90276100FB6730283E63F01D68A06884703EB04C647033D8D5B038D7F0483E903836DFC04750C8B45148945FC66B80D0A66AB85C90F8F69FFFFFFC607005F5E5BC9C21000" Local $CodeBuffer = DllStructCreate("byte[" & BinaryLen($Opcode) & "]") DllStructSetData($CodeBuffer, 1, $Opcode) $Data = Binary($Data) Local $Input = DllStructCreate("byte[" & BinaryLen($Data) & "]") DllStructSetData($Input, 1, $Data) $LineBreak = Floor($LineBreak / 4) * 4 Local $OputputSize = Ceiling(BinaryLen($Data) * 4 / 3) $OputputSize = $OputputSize + Ceiling($OputputSize / $LineBreak) * 2 + 4 Local $Ouput = DllStructCreate("char[" & $OputputSize & "]") DllCall("user32.dll", "none", "CallWindowProc", "ptr", DllStructGetPtr($CodeBuffer), _ "ptr", DllStructGetPtr($Input), _ "int", BinaryLen($Data), _ "ptr", DllStructGetPtr($Ouput), _ "uint", $LineBreak) Return DllStructGetData($Ouput, 1) EndFuncMy question is do I need to use WinHttp.au3 to take the place of WebClient and UploadValues? The Imgur documentation says to post a Base64 encoded image to this address: https://api.imgur.com/3/imageMethodPOSTRoutehttps://api.imgur.com/3/imageAlternative Routehttps://api.imgur.com/3/uploadResponse ModelBasicParametersKeyRequiredDescriptionimagerequiredA binary file, base64 data, or a URL for an image. (up to 10MB)albumoptionalThe id of the album you want to add the image to. For anonymous albums, {album} should be the deletehash that is returned at creation.typeoptionalThe type of the file that's being sent; file, base64 or URLnameoptionalThe name of the file, this is automatically detected if uploading a file with a POST and multipart / form-datatitleoptionalThe title of the image.descriptionoptionalThe description of the image.Any help that you can provide will be appreciated. Edited July 20, 2015 by jaberwacky edited code Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum?
jaberwacky Posted July 20, 2015 Posted July 20, 2015 Ok, I think I'm starting to put together some sort of picture here.$w.Headers.Add("Authorization", "Client-ID Put your client id here")is:_WinHttpAddRequestHeaders("Authorization", "Client-ID Put your client id here")and this:Local $responseArray = $w.UploadValues("https://api.imgur.com/3/image", $base64_image)is:_WinHttpSendRequest("https://api.imgur.com/3/image", $base64_image)Along with any required startup procedures? Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum?
trancexx Posted July 20, 2015 Author Posted July 20, 2015 Probably.This could also work (maybe):#include "WinHttp.au3" Const $sClientID = "3fda9b4a8bc150c" ; your client-id Const $sAddress = "https://api.imgur.com/3/upload.xml" ; the address of the target (https or http, makes no difference - handled automatically) Const $sForm = _ '<form action="' & $sAddress & '" method="post" enctype="multipart/form-data">' & _ ' <input type="file" name="image"/>' & _ ; '</form>' $sFileToUpload = FileOpenDialog("Open", @ScriptDir, "Images (*.jpg;*.gif;*.png;*.bmp)") ; Initialize and get session handle $hOpen = _WinHttpOpen() $hConnect = $sForm ; will pass form as string so this is for coding correctness because $hConnect goes in byref ; Fill form $sReturned = _WinHttpSimpleFormFill($hConnect, $hOpen, _ Default, _ "name:image", $sFileToUpload, _ "Authorization: Client-ID " & $sClientID) If @error Then MsgBox(4096, "Error", "Error number = " & @error) Else ConsoleWrite($sReturned & @CRLF) EndIf ; Close handles _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) jaberwacky 1 ♡♡♡ . eMyvnE
jaberwacky Posted July 20, 2015 Posted July 20, 2015 (edited) Awesome! It works thanks to your superior interlect. Thank you.There is one small problem though. It fails with error 4 on a 2mb image. Imgur can accept up to 10mb so I don't know where the issue lies. I was hoping you might know. Edited July 20, 2015 by jaberwacky typo fail Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum?
wakillon Posted July 20, 2015 Posted July 20, 2015 Awesome! It works thanks to your superior interlect. Thank you.There is one small problem though. It falls with error 4 on a 2mb image. Imgur can accept up to 10mb so I don't know where the issue lies. I was hoping you might know.Is it an animated gif ?Because Imgur limit animated gif to 2mb. AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts
jaberwacky Posted July 20, 2015 Posted July 20, 2015 jpgI uploaded it with your TinyPicSharer just now actually. Here it is: Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum?
wakillon Posted July 20, 2015 Posted July 20, 2015 jpgI uploaded it with your TinyPicSharer just now actually. Here it is:Hidden Contenti have resized your picture and get a 5.43MB file who was slowly but succesfully uploaded with TinyPicSharer.But i do not use the _WinHttpSimpleFormFill function.Look at the source. AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts
jaberwacky Posted July 20, 2015 Posted July 20, 2015 I have surgically examined your source. Combed through it with a fine comb. I finally came to the realization that your code uses version 2 of the Imgur API for which I can no longer receive a key. Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum?
trancexx Posted July 21, 2015 Author Posted July 21, 2015 Awesome! It works thanks to your superior interlect. Thank you.There is one small problem though. It fails with error 4 on a 2mb image. Imgur can accept up to 10mb so I don't know where the issue lies. I was hoping you might know.Maybe you need to verify your account to get that sizes. I don't know, sorry. ♡♡♡ . eMyvnE
wakillon Posted July 21, 2015 Posted July 21, 2015 (edited) I have surgically examined your source. Combed through it with a fine comb. I finally came to the realization that your code uses version 2 of the Imgur API for which I can no longer receive a key.Forget my suggestion.I just realize that my compiled version works, but not the script under 3.3.14.0 !i must investigate the problem.Edit : works under 3.3.12.0 Edited July 22, 2015 by wakillon AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts
trancexx Posted July 21, 2015 Author Posted July 21, 2015 Awesome! It works thanks to your superior interlect. Thank you.There is one small problem though. It fails with error 4 on a 2mb image. Imgur can accept up to 10mb so I don't know where the issue lies. I was hoping you might know.My outerlect was also useful this time. I know what's the problem. Imgur internally processes your file after the upload (validates, converts to whatever format) and this takes time. After they process the file they make a response. It appears for bigger files they need more than default 30 seconds that WinHTTP waits for server to reply. You can confirm this by yourself by changing/adding line to WinHttp.au3.So, if you want, find function __WinHttpFormSend() and add:_WinHttpSetTimeouts($hRequest, Default, Default, Default, 100000)...line just before:_WinHttpSendRequest($hRequest, Default, $sAddData) If you have slow internet add it like this:WinHttpSetTimeouts($hRequest, Default, Default, 100000, 100000) That will make WinHttp.au3 wait up to 100 seconds before returning. jaberwacky 1 ♡♡♡ . eMyvnE
jaberwacky Posted July 21, 2015 Posted July 21, 2015 This is a good day for the internet.It works! Thank you once again. Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum?
jaberwacky Posted July 21, 2015 Posted July 21, 2015 (edited) Look at the source.So I've been trying to see if I can make a version 3 function based on your function _HostImGurUpload and being informed by trancexx's code that she so graciously provided I get this:expandcollapse popupFunc _imgur_uploadur(Const $image_file) Local Const $hOpen = _WinHttpOpen("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)") ConsoleWrite("_WinHttpOpen" & @TAB & @error & @CRLF) Local Const $hConnect = _WinHttpConnect($hOpen, "api.imgur.com") ConsoleWrite("_WinHttpConnect" & @TAB & @error & @CRLF) Local Const $hRequest = _WinHttpOpenRequest($hConnect, "POST", "/3/upload.xml", "HTTP/1.1") ConsoleWrite("_WinHttpOpenRequest" & @TAB & @error & @CRLF) _WinHttpSetTimeouts($hRequest, 10000, 60000, 90000, 90000) ConsoleWrite("_WinHttpSetTimeouts" & @TAB & @error & @CRLF) Local Const $sContentType = "Content-Type: multipart/form-data;" _WinHttpSendRequest($hRequest, $sContentType, $WINHTTP_NO_REQUEST_DATA, $image_file) ConsoleWrite("_WinHttpSendRequest" & @TAB & @error & @CRLF) _WinHttpReceiveResponse($hRequest) ConsoleWrite("_WinHttpReceiveResponse" & @TAB & @error & @CRLF) Local $sReceivedData Switch _WinHttpQueryDataAvailable($hRequest) Case True ConsoleWrite("_WinHttpQueryDataAvailable" & @TAB & @error & @CRLF) Do $sReceivedData &= _WinHttpReadData($hRequest) If Not @extended Then ExitLoop EndIf ConsoleWrite($sReceivedData & @CRLF) Until False Switch StringInStr($sReceivedData, "error") Case True SetError (6) EndSwitch EndSwitch Local Const $iError = @error If $hRequest Then _WinHttpCloseHandle($hRequest) If $hConnect Then _WinHttpCloseHandle($hConnect) If $hOpen Then _WinHttpCloseHandle($hOpen) Return SetError($iError, 0, $sReceivedData) EndFuncThis function seems to connect to the the Imgur server but I get this as an error message:<?xml version="1.0" encoding="utf-8"?> <data type="array" success="0" status="400"><error>HTTP Access is disabled. Requests must use SSL (HTTPS).</error><request>/3/upload.xml</request><method>POST</method></data>Can anyone make out what this means and how to fix it please? I tried using "https://api.imgur.com" in the _WinHttpConnect function but no joy. Edit: might it have to do with this: _WinHttpOpenRequest($hConnect, "POST", "/3/upload.xml", "HTTP/1.1") <-- I wouldn't know what to change HTTP/1.1 to. Edit2: Well, I see a few more issues that I will need to sort out before this will work such as where to put the client id et cetera. Edited July 21, 2015 by jaberwacky Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum?
jaberwacky Posted July 21, 2015 Posted July 21, 2015 I think I have the HTTPS stuff figured out. Now it's on to providing my client id to Imgur. Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum?
trancexx Posted July 21, 2015 Author Posted July 21, 2015 If you use https then you have to use _WinHttpSendSSLRequest instead of _WinHttpSendRequest. Notice the SSL part.I could help you with the rest but I don't want to take that "Made it Ma! Top of the world!" feeling away from you. ♡♡♡ . eMyvnE
jaberwacky Posted July 21, 2015 Posted July 21, 2015 I assume that's _WinHttpSimpleSendSSLRequest? I could help you with the rest but I don't want to take that "Made it Ma! Top of the world!" feeling away from you.Is that a hint that I'm on the right trajectory? Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum?
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