flat assembler
Message board for the users of flat assembler.

Index > Windows > Using HttpSendRequest

Author
Thread Post new topic Reply to topic
tester3000



Joined: 16 Feb 2007
Posts: 17
tester3000
Please help need example using HttpSendRequest on FASM or MASM

I try to write a file uploader but I have troubles with HttpSendRequest

Code:
format PE GUI 4.0
entry start

include 'win32a.inc'

section '.data' data readable writeable

hInternet dd ?
hConnect  dd ?
hRequest  dd ?


INTERNET_OPEN_TYPE_PRECONFIG = 0
INTERNET_SERVICE_HTTP = 3
INTERNET_FLAG_KEEP_CONNECTION = 400000

lpszFile       db 'C:\file.txt',0
lpszAgent      db 'Mozilla/4.0 (compatible; MSIE 6.0b; Windows NT 5.0; .NET CLR 1.0.2914)',0
lpszServerName db 'localhost',0
lpszVerb       db 'POST',0
lpszObjectName db 'index.php',0
lpszHeaders    db 'Content-Type: application/x-www-form-urlencoded',13,10,0

lpnoopenfile    db 'Unable to open local file!',0
lpnosession     db 'Unable to create new remote session!',0
lpnoconnect     db 'There are no connection with remote host!',0Dh,'Please check is connection alive?',0
lpnorequest     db 'Unable to open request!',0
lpnosendrequest db 'Unable to send request!',0
lpuploadok      db 'Upload complete!',0
lpinfo          db 'File upload',0

section '.code' code readable executable
   start:
         invoke InternetOpen,lpszAgent,INTERNET_OPEN_TYPE_PRECONFIG,0,0,0
         test eax,eax
         jnz @F
         mov eax,lpnosession
         call ShowError
         jmp _exit

@@:
         mov [hInternet],eax
         invoke InternetConnect,eax,lpszServerName,80,0,0,INTERNET_SERVICE_HTTP,0,0
         test eax,eax
         jnz @F
         mov eax,lpnoconnect
         call ShowError
         jmp _close_inet

@@:
        mov [hConnect],eax
        invoke HttpOpenRequest,eax,lpszVerb,0,0,INTERNET_FLAG_KEEP_CONNECTION,0
        test eax,eax
        jnz @F
        mov eax,lpnorequest
        call ShowError
        jmp _close_inet


@@:
        mov [hRequest],eax
        invoke HttpSendRequest,eax,lpszHeaders,dwHeadersLength,lpOptional,dwOptionalLength
        test eax,eax
        jnz @F
        mov eax,lpnosendrequest
        call ShowError
        jmp _close_inet

@@:
        invoke MessageBox,0,lpuploadok,lpinfo,MB_ICONINFORMATION+MB_TOPMOST

_close_inet:
       invoke InternetCloseHandle,[hInternet]
_exit:
       invoke ExitProcess,0

proc ShowError
       invoke MessageBox,0,eax,0,MB_ICONERROR+MB_TOPMOST
       ret
endp

section '.idata' import data readable

library kernel,'KERNEL32.DLL',\
        wininet,'WININET.DLL',\
        user32,'USER32.DLL'

import kernel,\
       ExitProcess,'ExitProcess',\
       CloseHandle,'CloseHandle'

import wininet,\
       InternetOpen,'InternetOpenA',\
       InternetConnect,'InternetConnectA',\
       HttpOpenRequest,'HttpOpenRequestA',\
       HttpSendRequest,'HttpSendRequestA',\
       InternetCloseHandle,'InternetCloseHandle'    



index.php
Code:
<form action="http://localhost/upload.php" method="POST" enctype="multipart/form-data">
            <input type="file" name="file" size="40">
            <input type="submit" value="Upload">
</form>     


upload.php
Code:
<html>
<head>
<title>Result</title>
</head>
<body>
<?php
if($_FILES["filename"]["size"] > 1024*3*1024)
{
echo ("Max. file size is 3 mb");
exit;
}
if(copy($_FILES["filename"]["tmp_name"],
"c:/temp/".$_FILES["filename"]["name"]))
{
echo("File uploaded <br>");
echo("Filename: ");
echo($_FILES["filename"]["name"]);
echo("<br>Size: ");
echo($_FILES["filename"]["size"]);
echo("<br>Dir: ");
echo($_FILES["filename"]["tmp_name"]);
echo("<br>Type: ");
echo($_FILES["filename"]["type"]);
} else {
echo("Could not upload file");
}
?> 

</body>
</html>     
Post 08 Mar 2008, 22:23
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.