美文网首页
纯PowerBuilder实现url编码

纯PowerBuilder实现url编码

作者: 白龙马5217 | 来源:发表于2020-09-15 10:31 被阅读0次

如果url中包含特殊字符或汉字,需要编码后发送到服务器后台请求数据,一般浏览器都能自动url编码。

1 pb请求数据我用internetresult对象

继承internetresult创建一个Standard Class类,命名为n_cst_internet;完整代码如下:

forward
global type n_cst_internet from internetresult
end type
end forward

global type n_cst_internet from internetresult
end type
global n_cst_internet n_cst_internet

type variables
string is_data
inet in_cst_base
end variables
forward prototypes
public function integer internetdata (blob data)
public function string of_dec2hex (unsignedlong n10)
public function string of_urlencode (string as_url)
end prototypes

public function integer internetdata (blob data);//is_data   =  string(data , EncodingUTF8!) 

is_data   =  string(data,EncodingANSI!) 
//gb2312

return 1
end function

public function string of_dec2hex (unsignedlong n10);//10转16进制
//参数:n10 为10进制数
//返回:16进制字符串
//Create 2020-09-15 by 白龙马

char    HEXDIGIT[] = "0123456789ABCDEF"
string hex
long r
do while  n10> 15
    r = mod(n10,16)
    n10 /= 16
    hex = HEXDIGIT[r + 1] + hex
loop

hex = HEXDIGIT[n10 + 1] + hex
return hex
end function

public function string of_urlencode (string as_url);//url编码
//参数:url
//返回:编码后的url
//Create 2020-09-15 by 白龙马
long ll,lll,li
string ls_hex,ls_url='',cc

byte lb_array[]

lll = len(as_url)
for ll = 1 to lll
    cc = mid(as_url,ll,1)
    if match(cc,'[\-\_\.\/\?\:\=\%\(\)\,A-Za-z0-9]')=true then
        ls_hex = cc
    else        
        lb_array[] = getbytearray (blob (cc,encodingutf8!))
        ls_hex = ''
        for li = 1 to upperbound(lb_array)          
            ls_hex = ls_hex + '%' + of_dec2hex(lb_array[li])    //10转16进制
        next        
    end if  
    ls_url = ls_url + ls_hex
next

return ls_url

end function

on n_cst_internet.create
call super::create
TriggerEvent( this, "constructor" )
end on

on n_cst_internet.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on

2 pb使用n_cst_internet的get请求

//获取as_url的html
//参数:as_url
//返回:html 字符串

integer li_rtn,li_r
string ls_data,ls_url

in_cst_base = create inet
in_cst_internet = create n_cst_internet

ls_url = in_cst_internet.of_urlencode(as_url) //url编码

li_rtn = in_cst_base.geturl(ls_url,in_cst_internet)

if li_rtn = 1 then 
   ls_data = in_cst_internet.is_data
   return ls_data
else
    return ''
end if

相关文章

  • 纯PowerBuilder实现url编码

    如果url中包含特殊字符或汉字,需要编码后发送到服务器后台请求数据,一般浏览器都能自动url编码。 1 pb请求数...

  • urllib.parse模块使用

    url.parse :定义了url的标准接口,实现url的各种抽取 parse模块的使用:url的解析,合并,编码...

  • parse模块

    url.parse :定义了url的标准接口,实现url的各种抽取parse模块的使用:url的解析,合并,编码,...

  • xPath

    url.parse :定义了url的标准接口,实现url的各种抽取parse模块的使用:url的解析,合并,编码,...

  • Python爬虫 - parse模块常用方法

    url.parse:定义了url的标准接口,实现url的各种抽取 parse模块的使用:url的解析、合并、编码、...

  • ROR(47)url编码与Base64编码的区别

    URL 编码 Base64 编码的区别 1 url编码 1.1 什么是 url 编码 型如/url/?%E5%B9...

  • 服务器与浏览器之间的编码问题

    服务器与浏览器之间的编码问题 url编码 URL编码 1. 什么是url 2. 什么是url编码 2.1 在因特网...

  • Web 相关编码和转义

    常用编码 URL 编码 HTML 编码 JS 编码 URL编码 一般来说,URL只能使用英文字母(a-zA-Z)、...

  • URL编码

    介绍 URL 编码 URL 编码也被称为百分号编码。 URL 编码的规则:简单来说,如果需要对一个字符进行 URL...

  • URL 如何编码解码?为什么要编码

    title: URL 如何编码解码?为什么要编码tags: URLnotebook: 零散知识 URL 如何编码解...

网友评论

      本文标题:纯PowerBuilder实现url编码

      本文链接:https://www.haomeiwen.com/subject/cmvxyktx.html