Jump to content

HTTP request failing


Recommended Posts

Hi,

 

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"}'
$oHTTP.Send($sPD)
$oReceived = $oHTTP.ResponseText
$oStatusCode = $oHTTP.Status

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

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

 

Edited by lsakizada

Be Green Now or Never (BGNN)!

Link to comment
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, _
        $SECURITY_FLAG_IGNORE_UNKNOWN_CA, _
        $SECURITY_FLAG_IGNORE_CERT_CN_INVALID, _
        $SECURITY_FLAG_IGNORE_CERT_DATE_INVALID)
; set options
_WinHttpSetOption($hRequest, $WINHTTP_OPTION_SECURITY_FLAGS, $NewOption)

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

; Wait for the response
_WinHttpReceiveResponse($hRequest)

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

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

; Clean/Close handles
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

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

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

 

Be Green Now or Never (BGNN)!

Link to comment
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?

♡♡♡

.

eMyvnE

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...