jens42 Posted September 18, 2008 Share Posted September 18, 2008 (edited) Hi , I am trying to create a program which will upload an image to a website for decoding, I am using the HTTP UDF, here is what I have so far. #include <HTTP.au3> $host = "www.captchakiller.com" $page = "/api.php" $vars = "method=upload_captcha&api_key=(key here)&file=C:\testc.png&expire=60&rights=false" $data = _HTTPEncodeString($vars) $socket = _HTTPConnect($host) $recv = _HTTPRead($socket,1) _HTTPPost($host, $page, $socket, $data) _HTTPRead($socket,1) ConsoleWrite("Data received:"&@CRLF&$recv&@CRLF) The program will run, but Data recieved will be empty and I am clueless why. The website is captchakiller I am making this for a game which uses captchas to login. This is the requirement to use the api.php upload_captcha You must POST with "Content-Type: multipart/form-data". There are 5 required parameters: * method - upload_captcha * api_key - string representing the API key * file - transmit the CAPTCHA image * expire - number of seconds after which CAPTCHA has expired (usually 60 or 300) * rights - true or false Possible results: * FAILURE: access denied - get API key from website * FAILURE: file_size=0 * SUCCESS: captcha_id=<string GUID> I get no results just an empty space. I will be grateful if any one can help. Thanks Edited September 18, 2008 by jens42 Link to comment Share on other sites More sharing options...
ConsultingJoe Posted September 18, 2008 Share Posted September 18, 2008 That is a cool idea, however I think the problem is that your not uploading the file, your just telling it the destination. I think you need to do a fileread on that with that data as the file. I cant test it because I'm at work but I'm going to take a look at this later. [center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center] Link to comment Share on other sites More sharing options...
jens42 Posted September 19, 2008 Author Share Posted September 19, 2008 Great thnx for the reply, I'll work on that and tell you how it comes along Link to comment Share on other sites More sharing options...
ConsultingJoe Posted September 19, 2008 Share Posted September 19, 2008 (edited) Great thnx for the reply, I'll work on that and tell you how it comes alongI've been looking at it and I think HTTP.au3 needs to be modified for this method. Because its POST data and an encoded image if you look at the VB.NET exampleCODEPublic Function postCaptcha(ByVal strApiKey As String, ByVal strCaptchaFile As String) As String Dim objEncoding As New System.Text.UTF8Encoding Dim objStreamWriter As System.IO.StreamWriter Dim objStream As System.IO.Stream Dim objHTTPRequest As HttpWebRequest Dim sbPostData As New System.Text.StringBuilder Dim intUploadBit As Integer Dim intUploadSoFar As Integer Dim inttoUpload As Integer Dim i As Integer Dim objStreamReader As System.IO.Stream Dim strResult As String 'set request properties objHTTPRequest = System.Net.WebRequest.Create("http://www.captchakiller.com/api.php") objHTTPRequest.AllowAutoRedirect = True objHTTPRequest.Accept = "*/*" objHTTPRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705)" objHTTPRequest.KeepAlive = False objHTTPRequest.Timeout = 30000 objHTTPRequest.Method = "POST" objHTTPRequest.ContentType = "multipart/form-data; boundary=7cf2a327f01ae" sbPostData.Append("--" + "7cf2a327f01ae" + vbCrLf) sbPostData.Append("Content-Disposition: form-data; name=""api_key""" + vbCrLf) sbPostData.Append(vbCrLf) sbPostData.Append(strApiKey + vbCrLf) sbPostData.Append("--" + "7cf2a327f01ae" + vbCrLf) sbPostData.Append("Content-Disposition: form-data; name=""expire""" + vbCrLf) sbPostData.Append(vbCrLf) sbPostData.Append("1000" + vbCrLf) 'defaulted to 1000 but you can change this sbPostData.Append("--" + "7cf2a327f01ae" + vbCrLf) sbPostData.Append("Content-Disposition: form-data; name=""method""" + vbCrLf) sbPostData.Append(vbCrLf) sbPostData.Append("upload_captcha" + vbCrLf) sbPostData.Append("--" + "7cf2a327f01ae" + vbCrLf) sbPostData.Append("Content-Disposition: form-data; name=""rights""" + vbCrLf) sbPostData.Append(vbCrLf) sbPostData.Append("false" + vbCrLf) 'defaulted to false but you can change this 'this is the header for our captcha file upload sbPostData.Append("--" + "7cf2a327f01ae" + vbCrLf) sbPostData.Append("Content-Disposition: form-data; name=""file""; filename=""" & strCaptchaFile & "" + vbCrLf) sbPostData.Append("Content-Type: image/pjpeg" + vbCrLf) sbPostData.Append(vbCrLf) 'read our captch into a byte array Dim objBinReader As New BinaryReader(File.OpenRead(strCaptchaFile)) Dim bytPhotoContents As Byte() = objBinReader.ReadBytes(objBinReader.BaseStream.Length) objBinReader.Close() 'convert our other post data into a byte array Dim bytPostContents As Byte() = objEncoding.GetBytes(sbPostData.ToString) 'create a footer for insertation after the file bytes are uploaded Dim bytPostFooter As Byte() = objEncoding.GetBytes(vbCrLf + "--" + "7cf2a327f01ae" + vbCrLf) 'create a new data buffer to hold all of our byte arrays Dim bytDataBuffer As Byte() = New Byte(bytPostContents.Length + bytPhotoContents.Length + bytPostFooter.Length) {} 'copy the contents of our three byte arrays into our single byte array System.Buffer.BlockCopy(bytPostContents, 0, bytDataBuffer, 0, bytPostContents.Length) System.Buffer.BlockCopy(bytPhotoContents, 0, bytDataBuffer, bytPostContents.Length, bytPhotoContents.Length) System.Buffer.BlockCopy(bytPostFooter, 0, bytDataBuffer, bytPostContents.Length + bytPhotoContents.Length, bytPostFooter.Length) 'set the content length based on our new byte array length objHTTPRequest.ContentLength = bytDataBuffer.Length 'get our stream and post our data objStream = objHTTPRequest.GetRequestStream() 'chunk up our data and upload it to our stream 'will generally only need to send in one chunk unless file is large intUploadBit = Math.Max(bytDataBuffer.Length / 100, 50 * 1024) intUploadSoFar = 0 While i < bytDataBuffer.Length inttoUpload = Math.Min(intUploadBit, bytDataBuffer.Length - i) intUploadSoFar += inttoUpload objStream.Write(bytDataBuffer, i, inttoUpload) i = i + intUploadBit End While 'close our stream objStream.Close() 'get the response from the server Dim objHTTPResponse As HttpWebResponse = CType(objHTTPRequest.GetResponse(), HttpWebResponse) objStreamReader = objHTTPResponse.GetResponseStream() 'final result from server is returned to strResult Dim objStreamResult As New System.IO.StreamReader(objStreamReader) strResult = objStreamResult.ReadToEnd 'close our objects objStreamReader.Close() objStreamResult.Close() Return strResult End FunctionIt can be done tho. Edited September 19, 2008 by CyberZeroCool [center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center] Link to comment Share on other sites More sharing options...
ConsultingJoe Posted September 19, 2008 Share Posted September 19, 2008 I give up on this, sorry man. It's almost easier to just use IE.au3 to navigate through captchakiller.com; Login, Upload Captch, View Results. [center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center] 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