News:

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

HttpOpenRequest problem

Started by statis, July 19, 2011, 02:25:01 PM

Previous topic - Next topic

statis

Hello,

I need open request with multipart.

I finded this on C sample :
HINTERNET hRequest = HttpOpenRequest(hConnect, "POST",
      _T("FormActionHere"), NULL, NULL, accept, 0, 1)

Do you know value for "accept" in db form to set correctly my invoke in masm32 language ?

Tanks for all

ToutEnMasm

The answer is not in the wininet.h,so you have to search in your source code

dedndave

it is a pointer to a string that defines the mime-type(s)...
QuoteA pointer to a null-terminated array of strings that indicates media types accepted by the client. If this parameter is NULL, no types are accepted by the client. Servers generally interpret a lack of accept types to indicate that the client accepts only documents of type "text/*" (that is, only text documents—no pictures or other binary files). For more information and a list of valid media types, see http://www.iana.org/assignments/media-types/index.html.

Twister

The value is just "text/html"

dedndave

sounds like you could use NULL for HTML's   :P

statis

more informations
i have error with sendrequestheader when i send boundary
before studied rfc HttpOpenRequest does send accept value for multipart sending

if i anderstend your propositions i can try value:

db "accept",0

i try this tomorrow

thanks

statis

Quote from: dedndave on July 19, 2011, 03:35:28 PM
it is a pointer to a string that defines the mime-type(s)...
QuoteA pointer to a null-terminated array of strings that indicates media types accepted by the client. If this parameter is NULL, no types are accepted by the client. Servers generally interpret a lack of accept types to indicate that the client accepts only documents of type "text/*" (that is, only text documents—no pictures or other binary files). For more information and a list of valid media types, see http://www.iana.org/assignments/media-types/index.html.

"If this parameter is NULL, no types are accepted by the client", with null setting i have error boundary sending
i do sending form-data    but [RFC2388] isn't complete to set correctly parameters HttpOpenRequest's

tanks dednave

dedndave

try this...

        INVOKE  HttpOpenRequest,hConnect,chr$('POST'),chr$('FormActionHere'),NULL,NULL,chr$('text/html'),0,1

bomz

Quote.386
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\gdi32.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\wininet.inc
include \masm32\macros\macros.asm

includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\wininet.lib

SendRequest PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD
Main PROTO


.data
   UserAgent   db 'Mozilla/4.0 (compatible; MSIE 6.0b; Windows NT 5.0; .NET CLR 1.0.2914)',0
   fileUrl      db 'www.masm32.com',0
   method      db 'GET',0
   pageAddr   db '/board/index.php?topic=17065.new;boardseen#new',0
   ContentType   db 'Content-Type: zip',0
   fileSave   db 'index.html',0

.data?
   hInstance   dd ?
   hInternet   dd ?
   hConnect   dd ?
   hRequest   dd ?
   Bufferlen   dd ?
   Buffer      db 65536 dup(?)
   fHand      dd ?
   bwrite      dd ?

.code
start:
invoke InternetOpen, addr UserAgent,INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, NULL
mov hInternet,eax

invoke InternetConnect,hInternet, addr fileUrl,INTERNET_DEFAULT_HTTP_PORT, 0, 0,INTERNET_SERVICE_HTTP, 0, 0
mov hConnect,eax

invoke HttpOpenRequest,hConnect, addr method,addr pageAddr,0,0,0,0,0
mov hRequest,eax

invoke HttpSendRequest,hRequest, addr ContentType, sizeof ContentType, NULL, NULL

   invoke CreateFile, addr fileSave, GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ,\
   NULL,CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,NULL
   mov fHand, eax
download:
   invoke InternetReadFile,hRequest,addr Buffer, sizeof Buffer,addr Bufferlen
.if Bufferlen != 0
   invoke WriteFile, fHand, addr Buffer, sizeof Buffer, addr bwrite, NULL
   jmp short download
.endif
   invoke CloseHandle, fHand

invoke InternetCloseHandle,hRequest
invoke InternetCloseHandle,hConnect
invoke InternetCloseHandle,hInternet

   invoke   ExitProcess,eax
end start

statis

Quote from: dedndave on July 20, 2011, 02:54:01 AM
try this...

        INVOKE  HttpOpenRequest,hConnect,chr$('POST'),chr$('FormActionHere'),NULL,NULL,chr$('text/html'),0,1

sorry INVOKE  HttpOpenRequest,hConnect,chr$('POST'),chr$('FormActionHere'),NULL,NULL,chr$('text/html'),1 start error request

INVOKE  HttpOpenRequest,hConnect,chr$('POST'),chr$('FormActionHere'),NULL,NULL,1,1 doesn't start error request but later i have error with sending boundary

lplpszAcceptTypes value is mistery...

statis

tanks bomz your sample is useful for get method but for multipart sending with boundary it's post method needed

bomz

Quote.386
   .model flat,stdcall
   option casemap:none

   include \masm32\include\windows.inc
   include \masm32\include\user32.inc
   include \masm32\include\kernel32.inc
   include \masm32\include\wininet.inc
   includelib \masm32\lib\user32.lib
   includelib \masm32\lib\kernel32.lib
   includelib \masm32\lib\wininet.lib

.data
   UserAgent   db 'Mozilla/4.0 (compatible; MSIE 6.0b; Windows NT 5.0; .NET CLR 1.0.2914)',0
   fileUrl      db 'films-onep.ifolder.ru',0
   method      db 'POST',0
   pageAddr   db '/control/?file_id=***********************************************',0
   ContentType   db 'Content-Type: application/x-www-form-urlencoded',0
   fileSave   db 'noname.htm',0
   Adress      db 'http://films-onep.ifolder.ru/control/?file_id=15825290&code=*********************************',0
   CoockieData   db 'sid=98f0092f24f75ee82733deb8744e5ebf',0
   PostData   db 'prolong=%D0%BF%D1%80%D0%BE%D0%B4%D0%BB%D0%B8%D1%82%D1%8C',0
.data?
    hInternet   dd ?
    hConnect   dd ?
    hRequest   dd ?
    Bufferlen   dd ?
    Buffer      db 65536 dup(?)
    fHand      dd ?
    bwrite      dd ?

.code
start:
   invoke InternetOpen, addr UserAgent,INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, NULL
   mov hInternet,eax
   invoke InternetSetCookie, addr Adress,NULL,addr CoockieData
   invoke InternetConnect,hInternet, addr fileUrl,INTERNET_DEFAULT_HTTP_PORT, 0, 0,INTERNET_SERVICE_HTTP, 0, 0
   mov hConnect,eax
   invoke HttpOpenRequest,hConnect, NULL,addr pageAddr,0, addr Adress,0,0,0
   mov hRequest,eax
   invoke HttpSendRequest,hRequest, addr ContentType, sizeof ContentType, NULL, NULL
   invoke CreateFile, addr fileSave, GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ,\
   NULL,CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,NULL
   mov fHand, eax
download:
   invoke InternetReadFile,hRequest,addr Buffer, sizeof Buffer,addr Bufferlen
.if Bufferlen != 0
   invoke WriteFile, fHand, addr Buffer, Bufferlen, addr bwrite, NULL
   jmp short download
.endif
   invoke InternetCloseHandle,hRequest
   invoke HttpOpenRequest,hConnect, addr method,addr pageAddr,0, addr Adress,0,0,0
   mov hRequest,eax
   invoke HttpSendRequest,hRequest, addr ContentType, sizeof ContentType, addr PostData, sizeof PostData
   invoke CloseHandle, fHand
   invoke InternetCloseHandle,hRequest
   invoke InternetCloseHandle,hConnect
   invoke InternetCloseHandle,hInternet
   invoke ExitProcess,eax
end start

bomz

For some tasks better use SOCKET. For my case I do working application with SOCKET but when understand that it may not be fully correct and it's too complicated to learn all http protocol so I leave this idea

statis

Quote from: bomz on July 20, 2011, 11:41:20 AM
For some tasks better use SOCKET. For my case I do working application with SOCKET but when understand that it may not be fully correct and it's too complicated to learn all http protocol so I leave this idea

I have another post on same subject, use winsock is better solution for only one action, on in context i can't use winsocket for only very little part coding with only multipart form.

Isn't problem with http protocol, it's problème with api use i do specify call openrequest to send correctly boundary

bomz

In my application IE libruary some times work incorrectly. using socket more flexibly