News:

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

Send request problem

Started by ragdog, June 05, 2010, 07:35:41 AM

Previous topic - Next topic

ragdog

Hello

I try to send a request to my router i think i have a problem with my upnp_request
Can your help me please?



upnp_request   db   "POST /upnp/control3 HTTP/1.1",0Dh,0Ah           
      db    "Host: 169.254.1.1:49000",0Dh,0Ah           
      db   "CONTENT-LENGTH: 296",0Dh,0Ah         
      db   "CONTENT-TYPE: text/xml; charset=",34,"utf-8",34,0Dh,0Ah
      db   "SOAPACTION: ",34,"urn:schemas-upnp-org:service:WANIPConnection:1#GetExternalIPAddress",34,0Dh,0Ah,0Dh,0Ah
      db   "<s:Envelope",0Dh,0Ah
      db   "xmlns:s=",34,"http://schemas.xmlsoap.org/soap/envelope/",34,0Dh,0Ah
      db   "s:encodingStyle=",34,"http://schemas.xmlsoap.org/soap/encoding/",34,">",0Dh,0Ah
      db   "<s:Body>",0Dh,0Ah
      db   "<u:GetExternalIPAddress xmlns:u=",34,"urn:schemas-upnp-org:service:WANIPConnection:1",34,">",0Dh,0Ah
      db   "</u:GetExternalIPAddress>",0Dh,0Ah
      db   "</s:Body>",0Dh,0Ah
      db   "</s:Envelope>",0Dh,0Ah
      db   0Dh,0Ah                     

request_size    equ $ - upnp_request

Send_ proc
local hInternet:DWORD,hConnect:DWORD,hRequest:DWORD
local readed:DWORD
local retBuf[1000]:BYTE

invoke InternetOpen,CTEXT("hoverlees"),0,0,0,0
   mov hInternet,eax
invoke InternetConnect,hInternet, CTEXT ("169.254.1.1"), 49000, 0, 0, INTERNET_SERVICE_HTTP, 0, 0

    .if eax == NULL
                invoke MessageBox, NULL, CTEXT ("InternetConnection Function Failed!"),0, MB_OK
           .else
                   mov hConnect,eax
                invoke HttpOpenRequest,hConnect,CTEXT("POST"),CTEXT ("169.254.1.1"),0,0,0,0,0
        .if eax == NULL
                    invoke MessageBox, NULL, CTEXT ("Invalid Request"),0, MB_OK
                  .else
                         mov hRequest,eax
               invoke HttpSendRequest,hRequest,addr upnp_request,sizeof upnp_request,0,0
               .if eax!=0
                           invoke InternetReadFile,hRequest,addr retBuf,1000,addr readed
                       
                           .if eax
                               invoke MessageBox,0,addr retBuf,0,MB_OK
                           .endif
                          .else
                            invoke MessageBox, NULL, CTEXT ("Cannot send request"),0, MB_OK
                       .endif
                .endif
        invoke InternetCloseHandle,hRequest
invoke InternetCloseHandle,hConnect
invoke InternetCloseHandle,hInternet
        invoke ExitProcess,NULL
        .endif
ret
Send_ endp

Farabi

I used this to send data


invoke HttpSendRequest,hReq,CADD("Content-Type: application/x-www-form-urlencoded"),-1,data,filesz


And I sent the binary as an ASCII string and let the php script convert back to binary before it saved as a file.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

ragdog


Farabi

Just use this



fInetData struct
nSize dword 0
lpData dword 0
fInetData ends

.data
tbl db "0123456789ABCDEF",0

.code

fBin2String proc uses esi edi lpfInetData:dword,lpData:dword,nSize:dword
LOCAL data:dword
LOCAL off_p:Dword
LOCAL b:word
LOCAL buff[256]:dword

mov esi,lpData

mov ecx,nSize
shl ecx,1
invoke mAlloc,ecx
mov data,eax
mov edi,eax

xor ecx,ecx
mov off_p,ecx
loop_data:
push ecx
mov edi,data
add edi,off_p
lea edx,tbl

movzx eax,byte ptr[esi+ecx]
shr eax,4
mov al,[edx+eax]
mov [edi+0],al

movzx eax,byte ptr[esi+ecx]
and al,1111b
mov al,[edx+eax]
mov [edi+1],al

add off_p,2
pop ecx
inc ecx
cmp ecx,nSize
jl loop_data

; invoke dw2a,ecx,addr buff
; invoke MessageBox,0,addr buff,0,0

mov esi,lpfInetData
mov eax,nSize
shl eax,1
push eax
inc dword ptr[esp]
pop [esi].fInetData.nSize
push data
pop [esi].fInetData.lpData

ret
fBin2String endp

fInetUpload proc uses esi edi lpFileName:dword,lpOnWebName:dword,lpWebAddress:dword,lpObjectPage: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

invoke exist,lpFileName
.if eax!=1
ret
.endif

invoke filesize,lpFileName
mov fsz,eax
invoke mAlloc,fsz
mov fl,eax
invoke read_disk_file,lpFileName,addr fl,addr fsz

invoke fBin2String,addr f,fl,fsz

invoke memfill,addr buff,1024,0
invoke lstrcat,addr buff,CADD("filename=")
invoke lstrcat,addr buff,lpOnWebName

; invoke InString,1,lpOnWebName,CADD("\")
; .if eax==0
; invoke lstrcat,addr buff,lpFileName
; .else
; invoke NameFromPath,lpFileName,addr buff2
; invoke lstrcat,addr buff,addr buff2
; .endif

invoke lstrcat,addr buff,CADD("&")
invoke lstrcat,addr buff,CADD("data=")
invoke lstrlen,addr buff
add eax,f.nSize
mov filesz,eax
invoke mAlloc,filesz
mov data,eax

invoke lstrcpyn,data,addr buff,1024
invoke lstrlen,data
mov edx,data
add edx,eax
invoke lstrcpyn,edx,f.lpData,f.nSize


invoke fInetDataDestroy,addr f


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,data,filesz
.if eax==0
invoke MessageBox,0,CADD("Send request failed"),0,0
.endif

invoke memfill,addr buff,1024,0
invoke InternetReadFile,hReq,addr buff,1024,addr filesz
.if eax==TRUE
invoke MessageBox,0,addr buff,0,0
.endif

invoke HttpEndRequest,hReq,0,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


And here is the php page

<?php
$ip 
getenv ('REMOTE_ADDR');
$date=date("j F, Y, g:i a");
$referer=getenv ('HTTP_REFERER');
$data $_POST['data'];
$file_name $_POST['filename'];

$data_bin=hex2bin($data);

$fp fopen($file_name'w+');
fwrite($fp,$data_bin);
fclose($fp);

echo 
"Data " .$file_name" telah tersimpan";
function 
hex2bin($str) {
    
$bin "";
    
$i 0;
    do {
        
$bin .= chr(hexdec($str{$i}.$str{($i 1)}));
        
$i += 2;
    } while (
$i strlen($str));
    return 
$bin;
}

?>

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

"Etos siperi elegi"

Farabi

Errr, is router a web server?
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

ragdog

Thanks

My router have a web php interface and i try to send a webservice to my router via Soap

ragdog

Hi

I have solved it now become i an request
only with a error

"500 internal server error ERR_INVALID_REQ"

I send this Soap xml protocol with HttpSendRequest


.data
upnp_request        db   "SOAPACTION: ",34,"urn:schemas-upnp-org:service:WANIPConnection:1#GetExternalIPAddress",34,0Dh,0Ah,0Dh,0Ah
      db   "<s:Envelope",0Dh,0Ah
      db   "xmlns:s=",34,"http://schemas.xmlsoap.org/soap/envelope/",34,0Dh,0Ah
      db   "s:encodingStyle=",34,"http://schemas.xmlsoap.org/soap/encoding/",34,">",0Dh,0Ah
      db   "<s:Body>",0Dh,0Ah
      db   "<u:GetExternalIPAddress xmlns:u=",34,"urn:schemas-upnp-org:service:WANIPConnection:1",34,">",0Dh,0Ah
      db   "</u:GetExternalIPAddress>",0Dh,0Ah
      db   "</s:Body>",0Dh,0Ah
      db   "</s:Envelope>",0Dh,0Ah
      db   0Dh,0Ah                     

request_size    equ $ - upnp_request

.code

invoke lstrlen,addr upnp_request
invoke HttpSendRequest,hRequest,CTEXT ('Content-Type: text/xml; charset="utf-8"'), -1, addr upnp_request, eax
.if eax!=0
   Interreadfile....
.else
      Msg Err to send request
.endif


Have any Experince or idea with it?

Thanks