欢迎光临散文网 会员登陆 & 注册

【按键精灵】使用application/json请求头

2022-07-24 14:12 作者:酷玩蚊仔  | 我要投稿

Import "D:\按键精灵\按键精灵2014\plugin\vbsjson.vbs"

Set xPost = CreateObject("Msxml2.ServerXMLHTTP.3.0")

xPost.Open "Post", "http://localhost:80/api8?uid=3196036", False

//xPost.setRequestHeader "CONTENT-TYPE", "application/x-www-form-urlencoded" // 指定发送内容的编码类型

xPost.setRequestHeader "CONTENT-TYPE", "application/json" // 指定发送内容的编码类型

//xPost.Send ("a=酷玩&b=蚊仔")

//xPost.Send("{" & chr(34) & "a" & chr(34) & ": 18" & "}")

xPost.Send(jsonFormatter("a=酷玩&b=蚊仔"))

If xPost.readyState = 4 Then 

TracePrint TypeName(xPost.responsetext)

  TracePrint xPost.responsetext

  Set json = New vbsJson

  Set obj = json.Decode(xPost.responsetext)

  TracePrint obj("a")

End If

xPost.abort

Set xPost = Nothing




Function jsonFormatter(str)

result = "{"

attrList = split(str, "&")

For i = 0 To UBound(attrList)

If i > 0 Then 

result = result & ","

End If

attr = attrList(i)

key = split(attr, "=")(0)

value = split(attr, "=")(1)

result = result & chr(34) & key & chr(34) & ":" & chr(34) & value & chr(34)

Next

result = result & "}"

TracePrint result

jsonFormatter = result

End Function

【按键精灵】使用application/json请求头的评论 (共 条)

分享到微博请遵守国家法律