Jump to content
Sign in to follow this  

HTTP request failing

Recommended Posts



I am running this script against my site and it is return empty response in the message box.

What could be the problem? Is this related to JSon? or maybe HTTPS?


#include <array.au3>
$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("POST", "https://SITE.com/auth/signin", False)
$oHTTP.SetRequestHeader("Content-type", "application/json")
$oHTTP.SetRequestHeader("User-Agent", "User-Agent=Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0")
$sPD = '{"email":"test@EMAILEMAIL.com","password":"12345678"}'
$oReceived = $oHTTP.ResponseText
$oStatusCode = $oHTTP.Status

If $oStatusCode <> 200 Then
    MsgBox(4096, "Response code", $oStatusCode)

$file = FileOpen("Received.html", 2)
FileWrite($file, $oReceived)


Edited by lsakizada

Be Green Now or Never (BGNN)!

Share this post

Link to post
Share on other sites

I found a way to send the request by using this WinHTTP functions.

Unfortunately, I do not know how to retrieve the cookie in order to send it in next request.


Can you please give me a clue how to to perform it with WinHTTP functions?


#include "WinHttp.au3"

Opt("MustDeclareVars", 1)

Local $URL = "https://URL.com"
Local $Sources = "/auth/signin"
Local $Jason = '{"email":"test@MAILMAIL.com","password":"12345678"}'

Local $hOpen = _WinHttpOpen()
Local $hConnect = _WinHttpConnect($hOpen, $URL)

Local $hRequest = _WinHttpOpenRequest($hConnect, "post", $Sources, Default,  Default,  Default, $WINHTTP_FLAG_SECURE)
local $CurrentOption = _WinHttpQueryOption($hRequest, $WINHTTP_OPTION_SECURITY_FLAGS)
local $NewOption = BitOR($CurrentOption, _
; set options
_WinHttpSetOption($hRequest, $WINHTTP_OPTION_SECURITY_FLAGS, $NewOption)

; Send request
_WinHttpSendRequest($hRequest,"Content-type: application/json",$Jason)

; Wait for the response

; ...get full header
Local $sHeader = _WinHttpQueryHeaders($hRequest)

; ...get full data
Local $sData = _WinHttpReadData($hRequest)

; Clean/Close handles

; Display retrieved header
MsgBox(0, "Header", $sHeader)

; Display retrieved data
MsgBox(0, "Data", $sData)


Be Green Now or Never (BGNN)!

Share this post

Link to post
Share on other sites

Cookies are handled automatically, you don't have to do anything about them.
Once they are set, they are being sent with any new request. Considering cookie is property of a session, all you need to is not to close $hOpen handle and, of course, reuse it.

Why would you think you need to get and set cookie or whatever to make new request? Somebody said that?




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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...