Share this page 

Get data from the InternetTag(s): Powerscript

Create a new userobject from standard class internetresult, call it n_cst_internet.

Declare this instance variable

string is_data

With that userobject type, you need to overload the internetdata function (which will be called by the PB VM automatically). The return type is integer and the parameter is data, its type is a blob.

[integer internetdata(blob data)]

is_data = string(data)
NOTE : Since PB10 is unicode-based (previous version were ansi-based), you may need to specify that result contains Ansi characters and not the default Unicode encoding.
[integer internetdata(blob data)]

is_data = String(data, EncodingANSI!)

Then from your script

integer li_rc
inet linet_main
n_cst_internet luo_data  // as defined above

linet_main = CREATE inet
luo_data = CREATE n_cst_internet

li_rc = &
  linet_main.GetURL("", luo_data)
IF li_rc = 1 THEN
   MessageBox("Data from Real's HowTo", luo_data.is_data)
   MessageBox("Data from Real's HowTo", "Oops rc:" + string(li_rc))

DESTROY luo_data
DESTROY linet_main
POSTing data maybe a little more tricky. You may need to set all the headers.
string httprequest,ls_header
String ls_url,ls_headers
long ll_ret
long ll_length
Blob lblb_args
inet linet_main
n_cst_internet luo_data

linet_main = CREATE inet

luo_data = CREATE n_cst_internet

ls_url = "http://localhost/mypage.jsp"
lblb_args = blob("foo=bar")
ll_length = Len(lblb_args)
ls_headers = "Content-Type: " + &
       "application/x-www-form-urlencoded~n" + &
       "Content-Length: " + String( ll_length ) + "~n~n"
ll_ret = libet_main.PostURL(ls_url,lblb_args,ls_headers,8080,luo_data)

Since PB10 is using Unicode to encode characters, code designed with PB9 (which is Ansi) with the PostURL function may not work. The fix is simple, specify the Ansi encoding in the Blob function.

lblb_args = Blob("foo=bar", EncodingAnsi!)