Jump to content
Baymax

Problem login site with winhttp

Recommended Posts

Baymax

Hi everybody.

I'm a newbie autoit. I want login site http://teespring.com/ by winhttp 

Here is my code 

#include <winhttp.au3>
#include <zlib.au3>
#include <string.au3>
#include <array.au3>

$hopen = _WinHttpOpen("Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0")
$hconnect = _WinHttpConnect($hopen,"https://teespring.com/login")
$hRequest = _WinHttpOpenRequest($hconnect,"GET","/login","HTTP/1.1",'','',$WINHTTP_FLAG_SECURE)
_WinHttpAddRequestHeaders($hRequest,"Host: teespring.com")
_WinHttpAddRequestHeaders($hRequest,"User-Agent: Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0")
_WinHttpAddRequestHeaders($hRequest,"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
_WinHttpAddRequestHeaders($hRequest,"Accept-Language: en-US,en;q=0.5")
_WinHttpAddRequestHeaders($hRequest,"Accept-Encoding: gzip, deflate")
_WinHttpSendRequest($hRequest)

If (_WinHttpReceiveResponse($hRequest)==1) Then
    Local $Header = _WinHttpQueryHeaders($hRequest)
    Local $Data = _WinHttpSimpleReadData($hRequest, 2)
    ConsoleWrite($Header)
    $cookie = _StringBetween($Header,"Set-Cookie: ",";")
    $data1 = BinaryToString(_ZLIB_GZUncompress($Data),4)
    $ls = StringRegExp($data1,'<meta content="(.+?)" name="csrf-token" />',3)
EndIf
_WinHttpCloseHandle($hrequest)
$post ="utf8=%E2%9C%93&authenticity_token="&__WinHttpURLEncode($ls[0])&"&email=baymax%40gmail.com&password=baymax"
MsgBox(0,'',$post)
ClipPut($post)
$hRequest = _WinHttpOpenRequest("POST","/sessions","HTTP/1.1",'','',$WINHTTP_FLAG_SECURE)
_WinHttpAddRequestHeaders($hRequest,'Host: teespring.com')
_WinHttpAddRequestHeaders($hRequest,'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8')
_WinHttpAddRequestHeaders($hRequest,'Accept-Language: en-US,en;q=0.5')
_WinHttpAddRequestHeaders($hRequest,'Accept-Encoding: gzip, deflate')
_WinHttpAddRequestHeaders($hRequest,'Referer: https://teespring.com/login')
_WinHttpAddRequestHeaders($hRequest,'Cookie: '&$cookie[0]&';'&$cookie[3])
_WinHttpAddRequestHeaders($hrequest,"Content-Length: "&StringLen($post))
_WinHttpSendRequest($hrequest,"Content-Type: application/x-www-form-urlencoded",$post)
_WinHttpCloseHandle($hrequest)

$hRequest = _WinHttpOpenRequest($hconnect,'GET','/','HTTP/1.1','','',$WINHTTP_FLAG_SECURE)
_WinHttpAddRequestHeaders($hRequest,'User-Agent: Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0')
_WinHttpAddRequestHeaders($hRequest,'Host: teespring.com')
_WinHttpAddRequestHeaders($hRequest,'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8')
_WinHttpAddRequestHeaders($hRequest,'Accept-Language: en-US,en;q=0.5')
_WinHttpAddRequestHeaders($hRequest,'Connection: keep-alive')
_WinHttpAddRequestHeaders($hRequest,'Cookie: '&$cookie[0]&';'&$cookie[3])
_WinHttpSendRequest($hRequest)
If (_WinHttpReceiveResponse($hRequest)==1) Then
    Local $Header = _WinHttpQueryHeaders($hRequest)
    Local $Data = _WinHttpSimpleReadData($hRequest, 2)
    ConsoleWrite($Header)
EndIf
_WinHttpCloseHandle($hrequest)

 But it not working. Help me?

Share this post


Link to post
Share on other sites
GMK

Not sure what your ultimate goal is here, but you might look into using _WinHttpSimpleFormFill to log in.

Share this post


Link to post
Share on other sites
GMK

Just noticed something: change Line 7 of your code

$hconnect = _WinHttpConnect($hopen,"https://teespring.com/login")

to

$hconnect = _WinHttpConnect($hopen,"teespring.com")

Share this post


Link to post
Share on other sites
trancexx

You could do it like this:

#include "WinHttp.au3"

$sEmail = "baymax@gmail.com"
$sPassword = "baymax"

; Open session
$hOpen = _WinHttpOpen()
; Connection to make
$hConnect = _WinHttpConnect($hOpen, "https://teespring.com")

; Fill the form
$sRead = _WinHttpSimpleFormFill($hConnect, "/login", Default, _
        "name:email", $sEmail, _
        "name:password",$sPassword)

; Close handles
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

ConsoleWrite($sRead & @CRLF)

 

Edited by trancexx

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
Baymax

You could do it like this:

#include "WinHttp.au3"

$sEmail = "baymax@gmail.com"
$sPassword = "baymax"

; Open session
$hOpen = _WinHttpOpen()
; Connection to make
$hConnect = _WinHttpConnect($hOpen, "https://teespring.com")

; Fill the form
$sRead = _WinHttpSimpleFormFill($hConnect, "/login", Default, _
        "name:email", $sEmail, _
        "name:password",$sPassword)

; Close handles
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

ConsoleWrite($sRead & @CRLF)

 

I want after Login i can take action in page such as upload new design,manager campaign or get messages

Share this post


Link to post
Share on other sites
trancexx

You can do that, there's API available. I just made a shirt to test it.

  • Like 1

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
Baymax

Please Show me your code to upload new design test on teesping. Thanks u

Share this post


Link to post
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

×