语法:
Syntax
servicereference.GetURL ( urlname, data )
Argument Description
servicereference Reference to the Internet service instance
urlname String specifying the URL whose source data is returned in data
data InternetResult descendant containing an overridden InternetData function that handles the HTML source for urlname
Return value
Integer. Returns values as follows:
1 Success
-1 General error
-2 Invalid URL
-4 Cannot connect to the Internet
例子:
This example calls the GetURL function. Iinet_base is an instance variable of type inet:
iir_msgbox = CREATE n_ir_msgbox
iinet_base.GetURL(sle_url.text, iir_msgbox)
调用成功实例:
窗口函数:wf_geturl()
integer li_rc ,li_rtn ,li_return
string ls_url ,ls_rtn ,ls_js ,ls_scc
blob lb_rtn
sailjson json //XML解析函数
inet iinet_base,iinet //inet类型变量
n_ir ir //InternetResult 类型变量
iinet_base = create inet
iinet = create inet
li_rc = GetContextService( "Internet", iinet_base ) //判断网络通畅
if li_rc <> 1 THEN
destroy iinet_base
destroy iinet
return -1
end if
ir = CREATE n_ir
li_rtn = iinet.GetURL('http://88.88.88.88:8083/telegram/outTelegram/openAutoTel/888792206',ir)
//调用GetURL ir获取返回xml
json = create sailjson
ls_js = ir.is_data //返回xml
json.parse( ls_js ) //XML传入解析函数
ls_scc = string(json.getattribute( 'success')) //获取指定字段值
if trim(ls_scc) ="true" then
li_return = 1
else
li_return = -1
end if
destroy iinet_base
destroy iinet
destroy ir
destroy json
return li_return
附件:XML解析函数和 InternetData 函数
InternetData 函数
类型:InternetResult
名称:n_ir
edit source:
forward
global type n_ir from internetresult
end type
end forward
global type n_ir from internetresult
end type
global n_ir n_ir
type variables
string is_data
blob ib_blob
boolean ib_finished
end variables
forward prototypes
public function integer internetdata (blob data)
public function boolean wf_get_data (ref string as_html, ref blob ab_blob)
end prototypes
public function integer internetdata (blob data);
//messagebox('返回结果',string(data))
ib_finished = False
ib_blob = data
is_data = string(data)
ib_finished = True
RETURN 0
end function
public function boolean wf_get_data (ref string as_html, ref blob ab_blob);
as_html = is_data
ab_blob = ib_blob
return ib_finished
end function
on n_ir.create
call super::create
TriggerEvent( this, "constructor" )
end on
on n_ir.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on
XML解析函数
类型:nonvisualobject
名称:sailjson
edit source:
forward
global type sailjson from nonvisualobject
end type
type json_pair from structure within sailjson
end type
end forward
type json_pair from structure
string name
any value
end type
global type sailjson from nonvisualobject
end type
global sailjson sailjson
type variables
/*
Sailjson:from www.pblsoft.com
Please reserve this information
Version:2.1
Release date:2016-1-13
update:add root is array. getrootarray
Version:2.0
Release date:2016-1-1
*/
private:
json_pair pairs[]
string is_json
char ichars[]
long idx, imaxlen
treeview tree
integer objectpcxidx, arraypcxidx, itempcxidx
string is_ident
public:
boolean ignoreCase = true
integer ilevel
string pair_index
//end variab
end variables
forward prototypes
public function string parse (string as_json)
public function integer getarray (string itemname, ref any va[])
public function boolean isarray (any value)
public function any getattribute (string itemname)
private function integer of_readobject (sailjson vjson, integer alevel)
private subroutine of_error (string msg)
private subroutine skipspc ()
private function long findpairindex (string as_name)
private function string of_getformat (sailjson ajson, string ident)
private function string mymid (character vchars[], long vstart, long vlen)
public subroutine buildtree (tree