News:

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

Im stuck for years

Started by Farabi, January 28, 2010, 11:24:08 AM

Previous topic - Next topic

Farabi

Its been a couple years I figure out how this is works. I want to send my software update automatically and never works.


fInetUpload proc uses esi edi ;lpFileName:dword,lpWebAddress:dword
LOCAL hOpen,hCon,hReq,brcv:dword
LOCAL filesz,mem_handle:dword
LOCAL buff[256]:dword
LOCAL ibf :INTERNET_BUFFERS
LOCAL m: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,CADD("fSoftUpdate.awardspace.com"),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"),CADD("uploader2.php"),CADD("HTTP/1.1"),0,0,0,1
.if eax==0
invoke MessageBox,0,CADD("HttpOpenRequest Failed"),0,0
invoke PostQuitMessage,0
.endif
mov hReq,eax

;invoke HttpAddRequestHeaders,hReq,CADD("POST /uploader2.php HTTP/1.1"),-1,HTTP_ADDREQ_FLAG_ADD
;invoke HttpAddRequestHeaders,hReq,CADD("Host: antihack1221.awardspace.com"),-1,HTTP_ADDREQ_FLAG_ADD
  invoke HttpAddRequestHeaders,hReq,addr hRequest3,sizeof hRequest3,HTTP_ADDREQ_FLAG_ADD
  invoke HttpAddRequestHeaders,hReq,addr hRequest4,sizeof hRequest4,HTTP_ADDREQ_FLAG_ADD
  invoke HttpAddRequestHeaders,hReq,addr hRequest5,sizeof hRequest5,HTTP_ADDREQ_FLAG_ADD
  invoke HttpAddRequestHeaders,hReq,addr hRequest6,sizeof hRequest6,HTTP_ADDREQ_FLAG_ADD
  invoke HttpAddRequestHeaders,hReq,addr hRequest7,sizeof hRequest7,HTTP_ADDREQ_FLAG_ADD
  invoke HttpAddRequestHeaders,hReq,addr hRequest8,sizeof hRequest8,HTTP_ADDREQ_FLAG_ADD
  invoke HttpAddRequestHeaders,hReq,addr hRequest9,sizeof hRequest9,HTTP_ADDREQ_FLAG_ADD
  invoke HttpAddRequestHeaders,hReq,addr hRequestA,sizeof hRequestA,HTTP_ADDREQ_FLAG_ADD
  invoke HttpAddRequestHeaders,hReq,addr hRequestB,sizeof hRequestB,HTTP_ADDREQ_FLAG_ADD
  ; invoke HttpAddRequestHeaders,hReq,addr hRequestC,sizeof hRequestC,HTTP_ADDREQ_FLAG_ADD
 
  ; invoke HttpAddRequestHeaders,hReq,CADD("---------------------------247672365515574"),-1,HTTP_ADDREQ_FLAG_ADD
  ; invoke HttpAddRequestHeaders,hReq,CADD('Content-Disposition: form-data  name="MAX_FILE_SIZE" '),-1,HTTP_ADDREQ_FLAG_ADD
  ; invoke HttpAddRequestHeaders,hReq,CADD('10000 '),-1,HTTP_ADDREQ_FLAG_ADD
  ; invoke HttpAddRequestHeaders,hReq,CADD("---------------------------247672365515574"),-1,HTTP_ADDREQ_FLAG_ADD
  ;
invoke HttpAddRequestHeaders,hReq,addr hRequest2,-1,HTTP_ADDREQ_FLAG_ADD
invoke HttpAddRequestHeaders,hReq,addr hRequest,-1,HTTP_ADDREQ_FLAG_ADD
;
; invoke HttpAddRequestHeaders,hReq,CADD("test"),-1,HTTP_ADDREQ_FLAG_ADD
;
;invoke HttpAddRequestHeaders,hReq,CADD("---------------------------247672365515574"),-1,HTTP_ADDREQ_FLAG_ADD


; lea edx,FrmData5
; lea eax,FrmData
; sub edx,eax

; invoke HttpSendRequest,hReq,0,0,CADD("Test"),4
; .if eax==0
; invoke PERR
; .endif

push sizeof INTERNET_BUFFERS
pop ibf.dwStructSize
push 1024
pop ibf.dwBufferTotal
push offset hRequest
pop ibf.lpcszHeader

mov eax,offset hRequestC
sub eax,offset hRequest

;push sizeof hRequest
push eax
pop ibf.dwHeadersLength
push sizeof hRequest
pop ibf.dwHeadersTotal
push 0
pop ibf.lpvBuffer
push 0
pop ibf.dwBufferLength
push 4
pop ibf.dwBufferTotal
push 0
pop ibf.dwOffsetLow
push 0
pop ibf.dwOffsetHigh
;invoke HttpSendRequestEx,hReq,addr ibf,0,0,0

invoke HttpSendRequest,hReq,CADD("Content-Length: 10000 "),-1,CADD("Test"),10000
.if eax==0
invoke MessageBox,0,CADD("Send request failed"),0,0
.endif


mov m,1024
; invoke InternetWriteFile,hReq,addr buff,m,addr filesz
; .if eax==0
; invoke MessageBox,0,CADD("Write Error"),0,0
; .endif
invoke HttpEndRequest,hReq,0,0,0


invoke InternetReadFile,hReq,addr buff,1024,addr filesz
invoke MessageBox,0,addr buff,0,0

push 1024
pop mem_handle
invoke HttpQueryInfo,hReq,HTTP_QUERY_STATUS_TEXT,addr buff,addr mem_handle,0
invoke MessageBox,0,addr buff,0,0

invoke InternetCloseHandle,hCon
invoke InternetCloseHandle,hOpen
invoke InternetCloseHandle,hReq



ret
fInetUpload endp


I dont know what was wrong with this, I've tried using fidler to reconstruct what I should send but got no luck. Always return "Entity too large" or "Send request failed".
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Farabi

Here is the php page.
Quote
<?php
$target_path = "Uploaded/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']).
    " has been uploaded";
} else{
    echo "Ada kesalahan waktu anda mengunggah berkas ". $target_path . " , coba lagi!";
}
?>
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

oex

You will need the MAX_FILE_SIZE field if your post is more than 2Mb in total, also there may be server side parameters set blocking max file size set in php.ini http://www.theadminzone.com/forums/showthread.php?t=18182.... I've only had a very quick look but have you checked with a small file?

Also content disposition should be 'multipart/form-data'
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

oex

This is the basic form you want to emulate.... Test both parts of your submission seperately ie test the php first by submitting the html form below through the web browser

<form method="POST" name="FormName" enctype="multipart/form-data" action="http://www.post_url.com/">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input type="file" name="FileField">
<input type="submit" name="Submit" value="Submit">
</form>
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

Farabi

Quote from: oex on January 28, 2010, 01:30:00 PM
This is the basic form you want to emulate.... Test both parts of your submission seperately ie test the php first by submitting the html form below through the web browser

<form method="POST" name="FormName" enctype="multipart/form-data" action="http://www.post_url.com/">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input type="file" name="FileField">
<input type="submit" name="Submit" value="Submit">
</form>

This is what I shoudl send right?

Quote
hRequest db 'Content-Type: application/octet-stream',0,10
   hRequest2 db 'Content-Disposition: form-data; name="uploadedfile"; filename="gun.jpg" ',0,10
   hRequest3 db'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; id; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7 (.NET CLR 3.5.30729)',13,10
   hRequest4 db 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',13,10
   hRequest5 db 'Accept-Language: id,en-us;q=0.7,en;q=0.3',13,10
   hRequest6 db 'Accept-Encoding: gzip,deflate',13,10
   hRequest7 db 'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7',13,10
   hRequest8 db 'Keep-Alive: 10',13,10
   hRequest9 db 'Connection: keep-alive',13,10
   hRequestA db 'Referer: Farabi Application',13,10
   ; Entity
   hRequestB db 'Content-Type: multipart/form-data; boundary=---------------------------247672365515574',13,10
   hRequestC db 'Content-Length: 4',13,10
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Farabi

Quote from: oex on January 28, 2010, 01:30:00 PM
This is the basic form you want to emulate.... Test both parts of your submission seperately ie test the php first by submitting the html form below through the web browser

<form method="POST" name="FormName" enctype="multipart/form-data" action="http://www.post_url.com/">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input type="file" name="FileField">
<input type="submit" name="Submit" value="Submit">
</form>

Its works. I can uploaded the file.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

oex

We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

Farabi

Quote from: oex on January 29, 2010, 03:25:26 AM
:bg

Not yet, I still cannot upload the file from my application. Had any idea?
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

oex

ok you are confusing request and response from server....

   hRequest4 db 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',13,10
   hRequest5 db 'Accept-Language: id,en-us;q=0.7,en;q=0.3',13,10
   hRequest6 db 'Accept-Encoding: gzip,deflate',13,10
   hRequest7 db 'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7',13,10
delete these.... not required on client only on server

you also have 2 content-type headers
hRequest db 'Content-Type: application/octet-stream',0,10 delete this one
hRequestB db 'Content-Type: multipart/form-data; boundary=---------------------------247672365515574',13,10


Setup a local server if you know how and create the following html file on your desktop:
<form method="POST" name="FormName" enctype="multipart/form-data" action="http://127.0.0.1:80">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input type="file" name="FileField">
<input type="submit" name="Submit" value="Submit">
</form>

then read the data when you submit the form
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

oex

I didnt download the code but found this post:

http://www.masm32.com/board/index.php?topic=3109.msg24059#msg24059

If you can post the html file to a locally created server on 127.0.0.1 (localhost) you will have data that firefox/ie sends from which you will be able to see where you are going wrong
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

Farabi

Dont know how to setup a local server, I heard that I need to install apache or something.

So I tried it like this
Quote
invoke HttpAddRequestHeaders,hReq,CADD("Content-Type: application/x-www-form-urlencoded"),-1,HTTP_ADDREQ_FLAG_ADD
   invoke HttpAddRequestHeaders,hReq,CADD('name="uploadedfile"; filename="gun.jpg"'),-1,HTTP_ADDREQ_FLAG_ADD
   
   
   
   invoke HttpSendRequest,hReq,0,0,CADD("Test"),4
   .if eax==0
      invoke MessageBox,0,CADD("Send request failed"),0,0
   .endif

Where Should I put the data I need to write to the server? On HttpSendRequest right?
There are no any comprehensive example code that working for uploading a text file to the server, even from MS.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

oex

Hi Farabi,

Did you check out the link I posted? It has server code:
http://www.masm32.com/board/index.php?topic=3109.msg24059#msg24059

If you (check) and run server then post a html form to the IP 127.0.0.1 and Port the server is running on then read the received data you will see exactly what is being posted
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

Farabi

Quote from: oex on January 30, 2010, 01:54:31 PM
Hi Farabi,

Did you check out the link I posted? It has server code:
http://www.masm32.com/board/index.php?topic=3109.msg24059#msg24059

If you (check) and run server then post a html form to the IP 127.0.0.1 and Port the server is running on then read the received data you will see exactly what is being posted

Oh okay, thanks.
Anyway I had an alternative, using libcurl. But the library a little big, but save time from confusion.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Farabi

I see, so the data is sent but the server did not respond. Dont know what to do next. I build the same data except I did not use cookies but the serve still did not respond, dont know how to send cookie.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Farabi

Please use sampleserver and check out the data sent by my app to the server
http://omploader.org/vM2Y3bA/Net.zip

The server is not responding but I dont know what was wrong.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"