VBS脚本发送Http请求(Get,Post)

发送Get请求

 

发送Post请求:(包括json格式的内容)

Function sendHttpPost(posturl,params)
    Dim http
    Set http = CreateObject("MSXML2.ServerXMLHTTP")
    http.Open "POST",posturl,False,"",""
    http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    http.Send(params)
    If http.Status = "200" Then
        sendHttpPost = http.responseText
    Else
        sendHttpPost = http.Status & "<br />" & http.responseText
    End If
    Set http = nothing 
End Function 

' 发送json内容
Function sendHttpPost2(posturl,params)
    Dim http
    Set http = CreateObject("MSXML2.ServerXMLHTTP")
    http.Open "POST",posturl,False,"",""
    http.setRequestHeader "Content-Type", "application/json"
    http.Send(params)
    If http.Status = "200" Then
        sendHttpPost2 = http.responseText
    Else
        sendHttpPost2 = http.Status & "<br />" & http.responseText
    End If
    Set http = nothing 
End Function 

' 使用
' ret = sendHttpPost("http://127.0.0.1:9090/", "{hello=123}")
' ret = sendHttpPost("http://localhost:8080/test03","id=231&name=Wee")
ret = sendHttpPost2("http://localhost:9999/user/login","{""username"":""admin"",""password"":""123456""}")

MsgBox ret

 

**

posted @ 2023-02-24 15:32  htj10  阅读(983)  评论(0编辑  收藏  举报
TOP