| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- Namespace httprequest
- Function Hello()
- End
- Class HttpRequest Extends HttpRequestBase
-
- Method New()
- End
-
- Protected
-
- Method OnSend( text:String ) Override
-
- Global id:=0
-
- id+=1
-
- #If __TARGET__="windows"
- _tmp=GetEnv( "TMP" )+"\mx2_wget-"+id+".txt"
- #Else
- _tmp="/tmp/mx2_wget-"+id+".txt"
- #endif
-
- 'WGET
- Local post_data:=_req="POST" ? " -post-data=~q"+text+"~q" Else ""
- Local cmd:="wget -q -T "+_timeout+" -O ~q"+_tmp+"~q --method="+_req+" --content-on-error"+post_data+" ~q"+_url+"~q"
-
- 'CURL
- ' Local cmd:="curl -s -m "+_timeout+" -o ~q"+_tmp+"~q ~q"+_url+"~q"
-
- _process=New Process
-
- _process.Finished=Lambda()
-
- If Not _process Return
-
- If _process.ExitCode=0
-
- _response=LoadString( _tmp )
-
- DeleteFile( _tmp )
-
- _status=200
-
- _process=Null
-
- SetReadyState( ReadyState.Done )
-
- Else
-
- DeleteFile( _tmp )
-
- _status=404
-
- _process=Null
-
- SetReadyState( ReadyState.Error )
-
- Endif
- End
-
- SetReadyState( ReadyState.Loading )
-
- _process.Start( cmd )
- End
-
- Method OnCancel() Override
-
- If Not _process Return
- DeleteFile( _tmp )
-
- _process.Terminate()
-
- _process=Null
-
- _status=-1
- SetReadyState( ReadyState.Error )
- End
-
- Private
-
- Field _process:Process
-
- Field _tmp:String
- End
|