Вверх ↑
Ответов: 1731
Рейтинг: 68
#1: 2012-08-14 17:34:50 ЛС | профиль | цитата
Делал для себя. Может кому пригодится.
Есть возможность назначить UserAgent.
hiHttp_Get.hws

func init
// add using module
sys.add_use('System.Net')
sys.add_use('System.IO')
sys.add_use('System.Text')

// initialize properties
this.setfield('hr', 'hr' + this.id)
blk_vars.println('private HttpWebRequest ' + this.hr + ';')
this.setfield('resp', 'resp' + this.id)
this.setfield('rd', 'rd' + this.id)
if(linked("ContentLength") and linked("doDownload"))
sys.add_var('cl', 'Int64')
end
if(linked("ContentType") and linked("doDownload"))
sys.add_var('ct', 'string')
end
if(linked("ResponseUri") and linked("doDownload"))
sys.add_var('ru', 'Uri')
end
if(linked("Headers") and linked("doDownload"))
sys.add_var('hs', 'WebHeaderCollection')
end
if(linked("IsFromCache") and linked("doDownload"))
sys.add_var('ifc', 'bool')
end
if(linked("IsMutuallyAuthenticated") and linked("doDownload"))
sys.add_var('ima', 'bool')
end
end

func doDownload(uri, filename)
sys.add_var_loc('result', 2)
blk.println(this.hr, ' = WebRequest.Create(', d("URI"), ') as HttpWebRequest;')
.println(this.hr, '.UserAgent = ', d("UserAgent"), ';')
.println('HttpWebResponse ', this.resp, ' = ', this.hr, '.GetResponse() as HttpWebResponse;')
.println('StreamReader ', this.rd, ' = new StreamReader(', this.resp, '.GetResponseStream(), Encoding.', this.props("Encoding").value,');')
if(linked("ContentLength"))
blk.println(this.cl, ' = ', this.resp, '.ContentLength;')
end
if(linked("ContentType"))
blk.println(this.ct, ' = ', this.resp, '.ContentType;')
end
if(linked("ResponseUri"))
blk.println(this.ru, ' = ', this.resp, '.ResponseUri;')
end
if(linked("Headers"))
blk.println(this.hs, ' = ', this.resp, '.Headers;')
end
if(linked("IsFromCache"))
blk.println(this.ifc, ' = ', this.resp, '.IsFromCache;')
end
if(linked("IsMutuallyAuthenticated"))
blk.println(this.ima, ' = ', this.resp, '.IsMutuallyAuthenticated;')
end
blk.println(this.result, ' = ', this.rd, '.ReadToEnd();')
event("onDownload", this.result)
blk.println(this.rd, '.Close();')
.println(this.resp, '.Close();')
event('onStop')
end

func doStop
blk.println(this.hr, '.Abort();')
end

func ContentLength
return(this.cl)
end

func ContentType
return(this.ct)
end

func ResponseUri
return(this.ru)
end

func Headers
return(this.hs)
end

func IsFromCache
return(this.ifc)
end

func IsMutuallyAuthenticated
return(this.ima)
end
HTTP_Get.ini

[About]
Version=1.1
Author=Dilma & Nic
Mail=support@hiasm.com

[Type]
Class=Element
Info=Makes a request to a Uniform Resource Identifier (URI)
Tab=Internet

[Property]
URI=Sets the URI that identifies the Internet resource|2|
UserAgent=Specify the UserAgent|2|
Encoding=Sets the encoding applied to the contents of the response|14|0|Default,ASCII,BigEndianUnicode,Unicode,UTF32,UTF7,UTF8

[Methods]
doDownload=Starts the request|1|0
doStop=Cancels a request to an Internet resource|1|0
onDownload=Occurs after a successful data download and writes them to the flow|2|0
*onStop=Occurs after finishing the request|2|0
*ContentLength=Returns the content length of data being received|3|1
*ContentType=Returns the content type of the data being received|3|2
*ResponseUri=Returns the URI of the Internet resource that actually responded to the request|3|0
*Headers=Returns a collection of header name-value pairs associated with this request|3|0
*IsFromCache=Returns a Boolean value that indicates whether this response was obtained from the cache|3|0
*IsMutuallyAuthenticated=Returns a Boolean value that indicates whether mutual authentication occurred|3|0
URI=Defines the URI that identifies the Internet resource|4|2
UserAgent=Defines UserAgent|4|2

Первый раз влезаю в дебри RTCG.
карма: 1

0