Jump to content

WinHTTP functions


trancexx
 Share

Recommended Posts

I have made this script to translate the string $textoatraducir from russian ( $sourcelang = 'ru' ) into english ( $resultlang = 'en' )

#include <WinHttpUTF-8.au3>
#include <File.au3>

$url = 'http://translate.google.com.uy'
$aurl = _WinHttpCrackUrl($url)
$sourcelang = 'ru'
$resultlang = 'en'
$textoatraducir = FileRead(@ScriptDir&'/textinrussian.txt')
MsgBox(0,'textoatraducir:',$textoatraducir)

$hOpen = _WinHttpOpen('Mozilla/5.0 (Windows; U; Windows NT 5.1; es-ES; rv:1.9.2.28) Gecko/20120306 Firefox/3.6.28 (.NET CLR 3.5.30729)')
$hConnect = _WinHttpConnect($hOpen,$aurl[2])

$sRead = _WinHttpSimpleFormFill($hConnect,'','gt-form','source',$textoatraducir,'gt-sl',$sourcelang,'gt-tl',$resultlang,'js','n','prev','_t','hl','es','name:ie','UTF-8','name:layout','2','name:eotf','1')

_FileCreate(@ScriptDir&'/translategoogleresult'&'-'&@MDAY&'-'&@MON&'-'&@YEAR&'-'&@HOUR&'-'&@MIN&'-'&@SEC&'.html')
$hfile = FileOpen(@ScriptDir&'/translategoogleresult'&'-'&@MDAY&'-'&@MON&'-'&@YEAR&'-'&@HOUR&'-'&@MIN&'-'&@SEC&'.html',129)
FileWrite($hfile,$sRead)
FileClose($hfile)

_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

In which I used the UDF 'WinHttpUTF-8.au3' which is WinHttp.au3 edited in the line circa 1312 (in _WinHttpSimpleFormFill function) so instead of

Local $sReturned = _WinHttpSimpleReadData($hRequest)
  If @error Then
   _WinHttpCloseHandle($hRequest)
   Return SetError(4, 0, "") ; either site is expiriencing problems or your connection
  EndIf

I put

Local $sReturned = _WinHttpSimpleReadData($hRequest,1)
  If @error Then
   _WinHttpCloseHandle($hRequest)
   Return SetError(4, 0, "") ; either site is expiriencing problems or your connection
  EndIf

so that when it reads the data it does it in UTF-8.

The problem is that I receive this as html in the result (I used pastehtml cause emoticons appeared in the code if i posted here in an spoiler):

http://pastehtml.com/view/brxbjx5je.html

With all the russian characters showing as '????' . I don't know what's wrong, Fileread reads the text in russian correctly as the Messagebox shows. I guess the problem is in _WinHttpSimpleFormFill but I thought that by editing the line that I said it would be solved.

Thanks for your help!

PS: If I try to translate from english into russian (To reproduce it: $sourcelang = 'en' , $resultlang = 'ru' and in $textoatraducir put some text in english) It does it correctly, as it shows the html of the response:

http://pastehtml.com/view/brxbxdjt6.html

Link to comment
Share on other sites

  • 2 months later...

how can I get the request cookie send to the website?

Example :

GET /watch?v=9I6zSTiiSbQ&feature=g-logo HTTP/1.1

Host: www.youtube.com

User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:12.0) Gecko/20100101 Firefox/12.0

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Accept-Language: vi-vn,vi;q=0.8,en-us;q=0.5,en;q=0.3

Accept-Encoding: gzip, deflate

Connection: keep-alive

Referer: http://www.youtube.com/

Cookie: use_hitbox=d5c5516c3379125f43aa0d495d100d6ddAEAAAAw; VISITOR_INFO1_LIVE=O0NtQs2MfRo; PREF=f1=10000000; s_tempdata-1540547959=context=G2a00092FOAAAAAAADAA

HTTP/1.1 200 OK

Cache-Control: no-cache

Content-Encoding: gzip

Content-Length: 29118

Content-Type: text/html; charset=utf-8

Date: Sun, 27 May 2012 07:42:08 GMT

Expires: Tue, 27 Apr 1971 19:44:06 EST

P3P: CP="This is not a P3P policy! See //support.google.com/accounts/bin/answer.py?answer=151657&hl=vi-VN for more info."

Server: wiseguy/0.6.11

Set-Cookie: recently_watched_video_id_list=1c1d94b46cca89cc82da6fb77e41d0f5WwEAAABzCwAAADlJNnpTVGlpU2JR; path=/; domain=.youtube.com

Set-Cookie: s_tempdata-1540547959=; path=/; domain=.youtube.com; expires=Thu, 01-Jan-1970 00:00:00 GMT

X-Content-Type-Options: nosniff

X-Frame-Options: SAMEORIGIN

I want to get "use_hitbox=d5c5516c3379125f43aa0d495d100d6ddAEAAAAw; VISITOR_INFO1_LIVE=O0NtQs2MfRo; PREF=f1=10000000; s_tempdata-1540547959=context=G2a00092FOAAAAAAADAA"

tks you (sorry, my EngLish is not good ;) )

Link to comment
Share on other sites

If you can't retrieve complete Cookie try this way

#include 'WinHttp.au3'

$sUrl = 'http://www.youtube.com/watch?feature=player_embedded&v=9I6zSTiiSbQ'
$hOpen = _WinHttpOpen ( 'Mozilla/4.0 (compatible; MSIE 8.0)' )
$aCrackedUrl = _WinHttpCrackUrl ( $sUrl )
$sHostName = $aCrackedUrl[2]
$sFileName = $aCrackedUrl[6]
$sExtra = $aCrackedUrl[7]
$hConnect = _WinHttpConnect ( $hOpen, $sHostName )
$hRequest = _WinHttpOpenRequest ( $hConnect, 'GET', $sFileName & $sExtra, 'HTTP/1.1' )
_WinHttpSendRequest ( $hRequest )
_WinHttpReceiveResponse ( $hRequest )
$iHeaderIndex=0
While 1
    $sCookie = _WinHttpQueryHeaders ( $hRequest, $WINHTTP_QUERY_SET_COOKIE, $WINHTTP_HEADER_NAME_BY_INDEX, $iHeaderIndex )
    If Not @error And $sCookie Then
        ConsoleWrite ( '! Cookie: : ' & $sCookie & @Crlf )
    Else
        ExitLoop
    EndIf
    $iHeaderIndex+=1
WEnd
_WinHttpCloseHandle ( $hRequest )
_WinHttpCloseHandle ( $hConnect )
_WinHttpCloseHandle ( $hOpen )
Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

  • 2 weeks later...

Hm, I'll see what's going down.

ProgAndy we should probably move this to some other, more reliable place.

Yes, move it. I think either google code or github is fine and I already have accounts (gitorious is also good I think). If you know a better place, say so.

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

  • 1 month later...

i'm having problems with my script.. im trying to post data to my online database by sending the data to a php file which then inserts it into the database... heres my code:

Global $LocalIP = "www.site.com"
Global $hw_open = _WinHttpOpen()
Global $hw_connect = _WinHttpConnect($hw_open, $LocalIP)
Global $hRequest = _WinHttpOpenRequest($hw_Connect, Default, "script.php")
$data = "data="&$string
_WinHttpSendRequest($hRequest)
_WinHttpPost($hRequest, $data)

im not sure what im doing wrong, can someone help me figure out how to

send $data to my php script?

Link to comment
Share on other sites

  • 3 weeks later...

Hi trancexx,

there seems to be some issue with _WinhttpCrackUrl(). It doesnt accept url great than 1024 in length.

Do these urls exist? Yes. the url in question is a malware link, hence not attached in this post.

regards

DeltaRocked.

I just tried really huge addresses (33125 characters) and it works fine for me. Edited by trancexx
Link to comment
Share on other sites

Hi TranceXX,

you are right in this regard , it seems its not the length but the content of the url . Now I wonder what it might be ??

the enclosed url in this post is enoded in base64 and *I hope I havent breached any of the Forum Rules by provinding a malicious URL - if so then Mods can delete it *

Most of the the links provided in the pastebin are all errornous as far winhttpcrackurl is concerned.

http://pastebin.com/qSGNx5Cr

In order to overcome this I am using stringsplit with delimiter being '?' and the remainder of the string is being used as an input for _WinhttpCrackURL

Regards

Deltarocked.

Edited by deltarocked
Link to comment
Share on other sites

  • 1 month later...

Hi TranceXX, there's something we need to do, to use a https proxy?

thanks for the work you made ;)

plz, code upload image http://imgchili.com

thank :(

that one is easy, why you don't start reading this topic and learn how to do it?

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Link to comment
Share on other sites

plz code upload http://imgchili.com, me do not

just ask for help in the help section for your problem ;) (specifically your doubt)

@TranceXX, when using a proxy server, the function _WinHttpQueryHeaders() hangs and sometimes it takes forever, is anything wrong with this function and use proxy servers?

thanks

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Link to comment
Share on other sites

Not that I know of.

What kind of proxy?

I was using a https proxy, and sometimes it hangs all the GUI, I used the consolewrite to know in which point it stops, and it was at _WinHttpQueryHeaders() (I only grab the headers/data if _WinHttpQueryDataAvailable is set to True)

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Link to comment
Share on other sites

I was using a https proxy, and sometimes it hangs all the GUI, I used the consolewrite to know in which point it stops, and it was at _WinHttpQueryHeaders() (I only grab the headers/data if _WinHttpQueryDataAvailable is set to True)

I think its "_WinHttpSendRequest" not "_WinHttpQueryDataAvailable" some time proxies consume too much time to send the request, specially the dead proxies; Try to set the timeout for request with this function "_WinHttpSetTimeouts".

73 108 111 118 101 65 117 116 111 105 116

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...