Jump to content

help with submitting POST data


Influx
 Share

Recommended Posts

Basically i want to submit a value for the post variable "test"

And this will not work.(i have tried all exapmples)

#include "WinHTTP.au3"

$type = WinHttpWrapper("odpoa.com/test.php", "POST", 'test=test')
MsgBox(64, "", $type)

Func WinHttpWrapper($URL, $Type, $Data = "", $username = "", $password = "", $protocall = "HTTP/1.1")
    $temp = SplitURL($URL)
    $Server = $temp[0]
    $Address = $temp[1]
    $hw_open = _WinHttpOpen("WinHTTP Example")
    $hw_connect = _WinHttpConnect($hw_open, $Server)
    $h_openRequest = _WinHttpOpenRequest($hw_connect, $Type, $Address, $protocall)
    _WinHttpSetCredentials($h_openRequest, $WINHTTP_AUTH_TARGET_SERVER, $WINHTTP_AUTH_SCHEME_BASIC, $username, $password)
    _WinHttpSendRequest($h_openRequest)
    _WinHttpWriteData($h_openRequest, $Data)
    $Response = _WinHttpReceiveResponse($h_openRequest)
    _WinHttpCloseHandle($h_openRequest)
    _WinHttpCloseHandle($hw_connect)
    _WinHttpCloseHandle($hw_open)
    Return $Response
EndFunc

Func SplitURL($URL)
    Dim $array[2]
    $split = SplitURLHelper($URL, 3)
    If $split == 0 Then
        $split = SplitURLHelper($URL, 2)
        $URL = StringRight($URL, $split)
        $array[0] = $URL
        Return $array
    EndIf
   
    $left = StringLeft($URL, $split)
    $right = StringRight($URL, $split)
   
    $split = SplitURLHelper($left, 2)
    $left = StringRight($left, $split)
   
    $array[0] = $left
    $array[1] = $right
    Return $array
EndFunc

Func SplitURLHelper($String, $pos)
    $split = StringInStr($String, "/", 0, $pos)
    If $split == 0 Then
        $split = StringInStr($String, "\", 0, $pos)
    EndIf
    Return $split
EndFunc
Link to comment
Share on other sites

$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oRet = _HTTPRequest($oHTTP, "POST", "http://odpoa.com/test.php", "test=test")
ConsoleWrite($oRet & @CRLF)

Func _HTTPRequest($oHTTP, $oMethod, $oURL, $oData = "")
    $oHTTP.Open($oMethod, $oURL, False)
    If $oMethod = "POST" Then $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
    $oHTTP.Send($oData)
    Return $oHTTP.ResponseText
EndFunc

# MY LOVE FOR YOU... IS LIKE A TRUCK- #
Link to comment
Share on other sites

This is corrected Code for WinHTTP.au3

You have to give the lentgh of the data in _WinHttpSendRequest. If you supply the data as Parameter, you can add it to _WinHttpSendRequest(, too :) Then, to receive data, you have to use _WinHttpReadData. Also, your SplitURL did not work, so I replaced it with CrackURL ( you also could remove user+pass parameters and use those from the URL instead :)

#include "WinHTTP.au3"

$type = WinHttpWrapper("http://www.snee.com/xml/crud/posttest.cgi", "POST", 'fname=_____FNAME______&lname=_____LNAME______')
MsgBox(64, "", $type)
 #include "WinHTTP.au3"

$type = WinHttpWrapper("http://odpoa.com/test.php", "POST", "test=test","Content-Type: application/x-www-form-urlencoded"&@CRLF)
MsgBox(64, "", $type)

Func WinHttpWrapper($URL, $Type, $Data = "",$sHeaders="", $username = "", $password = "", $protocall = "HTTP/1.1")
    $temp = _WinHttpCrackUrl($URL)
    $Server = $temp[2]
    $Address = $temp[6]&$temp[7]

    $hw_open = _WinHttpOpen("WinHTTP Example")
    $hw_connect = _WinHttpConnect($hw_open, $Server)
    $h_openRequest = _WinHttpOpenRequest($hw_connect, $Type, $Address, $protocall)
    _WinHttpSetCredentials($h_openRequest, $WINHTTP_AUTH_TARGET_SERVER, $WINHTTP_AUTH_SCHEME_BASIC, $username, $password)
    _WinHttpSendRequest($h_openRequest,$sHeaders,$Data,StringLen($Data))
    $Response = _WinHttpReceiveResponse($h_openRequest)
    If _WinHttpQueryDataAvailable($h_openRequest) Then
        $Response = ""
        Do
            $Response &= _WinHttpReadData($h_openRequest)
        Until @error <> 0
    EndIf
    _WinHttpCloseHandle($h_openRequest)
    _WinHttpCloseHandle($hw_connect)
    _WinHttpCloseHandle($hw_open)
    Return $Response
EndFunc
Edited by ProgAndy

*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

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