News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

problem with HttpSendRequest

Started by statis, April 09, 2011, 10:02:50 PM

Previous topic - Next topic

statis

Hello,

I have problem with HttpSendRequest

for download http page with authentification formulary :
<form action="index.php" method="post" name="connect" class="returninfo">
<input name="login" type="text" id="login">
<input name="pass" type="password" id="pass">
</form>

I use with MASM32:

wininet library/include and others

.data
NullString db 0
Name db "Authentification",0
Page db "http://xxx.yyy.zzz/index.php",0 ;no www it's intranet page
lpszVerbpost db "POST",0
formact db "index.php",0
hdrs db "Content-Type: application/x-www-form-urlencoded",0
frmdata db "login=x.xxx&pass=yyyy",0

.data?
hSession dd ?
hConnect dd ?

.code
main code and others

invoke InternetOpen,offset Name
mov hSession,eax
invoke InternetConnect,hSession,offset Page,INTERNET_DEFAULT_HTTP_PORT,offset NullString,0,INTERNET_SERVICE_HTTP,0,0
mov hConnect,eax   
invoke HttpOpenRequest,hConnect,offset lpszVerbpost,offset formact,0,0,0,0,0
mov hRequest,eax
invoke lstrlen,offset frmdata
mov ebx,eax
invoke HttpSendRequest,hRequest,offset hdrs,47,offset frmdata,ebx
invoke InternetReadFile,hRequest,........................

and with HttpSendRequest return eax=FALSE

I have try on another web page with similary forms and if i use http:// i have HttpSendRequest error, if i use directly www.... i have no error but all times i can't authentificate

Have you one solution ?

Thanks to all

Farabi

#1
I used this and find no error


fInetSendData proc uses esi edi lpWebAddress:dword,lpObjectPage:dword,lpData:dword,nData:dword
LOCAL hOpen,hCon,hReq,brcv:dword
LOCAL filesz,mem_handle:dword
LOCAL buff[256]:dword
LOCAL buff2[256]:dword
LOCAL ibf :INTERNET_BUFFERS
LOCAL m:dword
LOCAL f:fInetData
LOCAL data,fsz,fl:dword
LOCAL data_dir:dword


invoke InternetOpen,CADD("Farabi"),INTERNET_OPEN_TYPE_PRECONFIG,0,0,0
mov hOpen,eax
.if eax==0
invoke MessageBox,0,CADD("InternetOpen Failed"),0,0
invoke PostQuitMessage,0
.endif

invoke InternetConnect,hOpen,lpWebAddress,INTERNET_DEFAULT_HTTP_PORT,0,0,INTERNET_SERVICE_HTTP,0,1
.if eax==0
invoke MessageBox,0,CADD("InternetConnect"),0,0
invoke PostQuitMessage,0
.endif
mov hCon,eax
invoke HttpOpenRequest,hCon,CADD("POST"),lpObjectPage,CADD("HTTP/1.1"),CADD("Farabi Poll Application"),0,0,1
.if eax==0
invoke MessageBox,0,CADD("HttpOpenRequest Failed"),0,0
invoke PostQuitMessage,0
.endif
mov hReq,eax



invoke HttpSendRequest,hReq,CADD("Content-Type: application/x-www-form-urlencoded"),-1,lpData,nData
.if eax==0
;invoke MessageBox,0,CADD("Send request failed"),0,0
invoke InternetCloseHandle,hCon
invoke InternetCloseHandle,hOpen
invoke InternetCloseHandle,hReq
xor eax,eax
dec eax
ret
.endif

invoke mAlloc,1000000
mov data_dir,eax
invoke memfill,data_dir,1000000,0
; loop_retrieve_data:
invoke InternetReadFile,hReq, data_dir,1000000,addr filesz
; cmp eax,TRUE
; jnz loop_retrieve_data

; invoke MessageBox,0, data_dir,0,0

;invoke HttpEndRequest,hReq,0,0,0


invoke InternetCloseHandle,hCon
invoke InternetCloseHandle,hOpen
invoke InternetCloseHandle,hReq
mov eax,data_dir


ret
fInetSendData endp


How to use it

invoke fInetSendData,CADD("www.yourweb.com"),CADD("/yourdirectory/yourpage.php"),lpdatayouwanttopass,numberofdata
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

elmo

I think it's enough with the following code. (to download index.php from internet to your local hdd)
but, you must pass the same file' extension to InternetOpenUrl and CreateFile.
if don't it will be corrupted' file. lol




invoke InternetOpen,SADD("elmo"),INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,NULL
mov hSession,eax
.if hSession == INVALID_HANDLE_VALUE
mov eax,FALSE
ret
.endif


invoke InternetOpenUrl,hSession,SADD("http://blabla.com/index.php"),NULL,NULL,NULL,NULL
mov hUrl,eax
.if hUrl == INVALID_HANDLE_VALUE
mov eax,FALSE
invoke MessageBox,0,SADD("download fail"),SADD("result"),MB_OK
ret
.endif
invoke CreateFile,
SADD("C:\index.php"),
GENERIC_READ or GENERIC_WRITE,
FILE_SHARE_READ,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL
mov fHand,eax
.if fHand == INVALID_HANDLE_VALUE
mov eax,FALSE
invoke MessageBox,0,SADD("download fail"),SADD("result"),MB_OK
ret
.endif
invoke SetFilePointer,fHand,NULL,NULL,FILE_BEGIN
download:
invoke InternetReadFile,hUrl,addr Buffer,sizeof Buffer,addr Bufferlen
.if Bufferlen != 0
invoke WriteFile,fHand,addr Buffer,Bufferlen,ADDR bwrite,NULL
invoke SetWindowText,hEdit1,addr Buffer
jmp download
.endif
invoke CloseHandle,fHand
invoke InternetCloseHandle,hUrl
invoke InternetCloseHandle,hSession
mov eax,TRUE
invoke MessageBox,0,SADD("download ok"),SADD("result"),MB_OK
be the king of accounting programmer world!

statis

sorry Elmo but it's problem authentification not downloading page, http page is downloaded but not authentificated   :'(

Tanks Farabi but i can't try directly your proc my masm configuration don't will use CADD

This day i have n't access to my intranet page and i make tests with masm32 www.masm32.com/board/index.php page form :
<form action="http://www.masm32.com/board/index.php?action=login2" method="post" style="margin: 3px 1ex 1px 0; text align:right;">
<input type="text" name="user" size="10" /> <input type="password" name="passwrd" size="10" />
<select name="cookielength"><option value="60">1 Hour</option></select><input type="submit" value="Login" /><br />

I have good result with direct url request on webbrowser :
http://www.masm32.com/board/index.php?action=login2&user=xxxx&passwrd=yyyyy&cookielength=60
It's very nice for shorcut but not my way

I have new code with modifications,
lpszAgent                 db "Farabi",0
lpszServerName         db "www.masm32.com/board/index.php",0
lpszVerbpost      db "POST",0
lpszObjectName        db "www.masm32.com/board/index.php?action=login2",0
lpszVersion               db "HTTP/1.1",0
lpszReferer      db "Farabi Poll Application",0
lpszHeaders             db "Content-Type: application/x-www-form-urlencoded",0
lpOptional                db "user=xxxx&passwrd=yyyyy&cookielength=60"

hConnect                dd ?
hOpen                    dd ?
hOpenRequest         dd ?

INVOKE InternetOpen,offset  lpszAgent,INTERNET_OPEN_TYPE_PRECONFIG,0,0,0
;help on  http://msdn.microsoft.com/en-us/library/aa385096(v=vs.85).aspx
mov   hOpen,eax
or   eax,eax
jz   ErrorOpen

invoke InternetConnect,hOpen,offset lpszServerName,INTERNET_DEFAULT_HTTP_PORT,0,0,INTERNET_SERVICE_HTTP,0,1
;help on http://msdn.microsoft.com/en-us/library/aa384363(v=vs.85).aspx
mov   hConnect,eax
or   eax,eax
jz   ErrorConnect

invoke HttpOpenRequest,hConnect,offset lpszVerbpost,offset lpszObjectName,offset lpszVersion,offset lpszReferer,0,0,1
;i don't anderstand value lpszReferer "Farabi Poll Application"
;help on http://msdn.microsoft.com/en-us/library/aa384233(v=vs.85).aspx
mov    hOpenRequest,eax
or   eax,eax
jz   ErrorOpenRequest

invoke lstrlen,offset lpOptional
mov ebx,eax
invoke HttpSendRequest,hOpenRequest,offset lpszHeaders,-1,offset lpOptional,ebx
;help on http://msdn.microsoft.com/en-us/library/aa384247(v=vs.85).aspx
cmp eax,0
je ErrorSendRequest

And sorry i have error in SendRequest  :'(

I have modified lpszServerName to db "www.masm32.com" , no error SendRequest but result with InternetReadFile is :
The requested URL was not found on this server
I have modified lpszObjectName to db "/board/index.php?action=login2" , no error SendRequest but no result with InternetReadFile
I have modified lpszObjectName to db "/board/index.php?" , and lpOptional  to db "action=login2&user=statis&passwrd=azerty&cookielength=60", no error SendRequest but no result with InternetReadFile

Where is a problem    :'(

Farabi

Put this

literal_string      macro   lit_string
         local   local_string

         .data
         align   4
local_string      db   lit_string, 0

         .code
         exitm   <local_string>
         endm
CADD MACRO quoted_text
      LOCAL vname,lbl
        jmp lbl
          vname db quoted_text,0
        lbl:
      EXITM <ADDR vname>
    ENDM
CSTR         macro   lit_string
         exitm   <offset literal_string(lit_string)>
         endm

The problem is at the data you pass. For example, if you had a text box named "text" without quote, you should pass the data like this

invoke fInetSendData,CADD("www.yourweb.com"),CADD("/yourdirectory/yourpage.php"),CADD("text=mytext"),numberofdata

If there are 2 text box for example named "text1" and "text2" you will need to pass the data like this

invoke fInetSendData,CADD("www.yourweb.com"),CADD("/yourdirectory/yourpage.php"),CADD("text1=mytext&text2=mytext2"),numberofdata


Your object is named
Quote
<input type="text" name="user" size="10" /> <input type="password" name="passwrd" size="10" />

user and passwrd so you will need to pass the data like this


invoke fInetSendData,CADD("www.yourweb.com"),CADD("/yourdirectory/yourpage.php"),CADD("user=mytext&text2=passwrd"),numberofdata
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

statis

Thanks Farabi,you are the BestOne  :clap:

I have used your code, it's working and i anderstand CADD.

You have right, the problem is with directory

I have new code2 with modifications (sorry i don't like macros)
lpszAgent                 db "Authentification",0
lpszServerName         db "www.masm32.com",0
lpszVerbpost             db "POST",0
lpszObjectName        db "/board/index.php?action=login2",0
lpszVersion               db "HTTP/1.1",0
lpszHeaders              db "Content-Type: application/x-www-form-urlencoded",0
lpOptional                db "user=xxxx&passwrd=yyyyy&cookielength=60"

page                       db "www.masm32.com/board/index.php",0

hConnect                dd ?
hOpen                    dd ?
hOpenRequest         dd ?

INVOKE InternetOpen,offset  lpszAgent,INTERNET_OPEN_TYPE_PRECONFIG,0,0,0
;help on  http://msdn.microsoft.com/en-us/library/aa385096(v=vs.85).aspx
mov   hOpen,eax
or   eax,eax
jz   ErrorOpen

invoke InternetConnect,hOpen,offset lpszServerName,INTERNET_DEFAULT_HTTP_PORT,0,0,INTERNET_SERVICE_HTTP,0,1
;help on http://msdn.microsoft.com/en-us/library/aa384363(v=vs.85).aspx
mov   hConnect,eax
or   eax,eax
jz   ErrorConnect

invoke HttpOpenRequest,hConnect,offset lpszVerbpost,offset lpszObjectName,offset lpszVersion,0,0,0,1
;i have set lpszReferer to NULL
;help on http://msdn.microsoft.com/en-us/library/aa384233(v=vs.85).aspx
mov    hOpenRequest,eax
or   eax,eax
jz   ErrorOpenRequest

invoke lstrlen,offset lpOptional
mov ebx,eax
invoke HttpSendRequest,hOpenRequest,offset lpszHeaders,-1,offset lpOptional,ebx
;help on http://msdn.microsoft.com/en-us/library/aa384247(v=vs.85).aspx
cmp eax,0
je ErrorSendRequest

invoke InternetOpenUrl,hSession,offset Page,..... ;i don't if possible to use another way, InternetReadFile unsuccess with hRequest
.....
loopread:
invoke InternetReadFile,....
.....

And read page's is ok with authentification success NO ERROR SENDREQUEST  :bg

I do try with my intranet pag's tomorrow, it's more difficult, the "form" isn't same
for my intranet (doesn't work with direct URL):
<form action="index.php" method="post" name="connect" class="returninfo">
<input name="login" type="text" id="login">
<input name="pass" type="password" id="pass">
</form>
for masm32 forum (work with direct URL and now with SendRequest):
<form action="http://www.masm32.com/board/index.php?action=login2" method="post">
<input type="text" name="user" size="10" /> <input type="password" name="passwrd" size="10" />
<select name="cookielength"><option value="60">1 Hour</option></select><input type="submit" value="Login" />

Thanks.

statis

with correct lpszServerName and lpszObjectName, authentification on my intranet page's work
first page open with invoke InternetOpenUrl,hSession,offset Firstpage is ok
But for next step i do open new page and open with invoke InternetOpenUrl,hSession,offset Secondpage doesn't work.
No error but no data charged with invoke InternetReadFile.

Error SendRequest is gone  :U

I do make new post for new problem with wininet  :'(

It's very wild world for man without knowledge...