我们要用到的也是WebBrowser的“Navigate”方法,其函数原型如下所示:

Sub Navigate(URL As String, [Flags], [TargetFrameName], [PostData], [Headers])

新建一个工程,部件中勾选中 “Microsoft Internet Controls”,添加一个WebBrowser1、一个Command1在窗体上,可以把WebBrowser1适当拉大一点,Form1中添加以下代码:

Private Sub Command1_Click()

ReDim aByte(0) As Byte ' Array of bytes to hold data to post
   

    cPostData =
"login_name=帳號&password=密碼&cookietime=0&x=42&y=10"
   

    PackBytes aByte(), cPostData
   
    Dim vPost As Variant
   

    vPost = aByte ' Assign the byte array to a VARIANT
   
    Dim
vHeaders As Variant
   
    vHeaders = "Content-Type:
application/x-www-form-urlencoded" + Chr(10) + Chr(13)
   
   
WebBrowser1.Navigate "http://www.csdn.net/member/logon.asp",
, , vPost, vHeaders

End Sub

Private Sub PackBytes(ByteArray() As Byte, ByVal PostData As String)

iNewBytes = Len(PostData) - 1   ' Get rid of the null termination
   

    If iNewBytes < 0 Then
        Exit Sub
    End If
   

    ReDim ByteArray(iNewBytes)
   
    For i = 0 To iNewBytes
   

        ch = Mid(PostData, i + 1, 1)
        If ch = Space(1)
Then
            ch = "+"
        End If
        Debug.Print ch,
Asc(ch)
        ByteArray(i) = Asc(ch)
    Next
End Sub

Sub getWeb()
 
    Dim As XMLHTTP
    tmpth = "c:\temp.htm"
    URL = "http://www.baidu.com/"
    Set X = New XMLHTTP
    X.Open "GET", URL, False
    X.send
    s = X.responseText
    ss = "<body"
    arr = Split(s, ss)
    ss = ss & arr(1)
    If Dir(tmpth) <> "" Then Kill tmpth
 
    Open tmpth For Output As 1
    Print #1, , ss
    Close 1
    WebBrowser1.Navigate2 tmpth
    Set bd = WebBrowser1.Document.body
    Do While bd Is Nothing
        DoEvents
        Set bd = WebBrowser1.Document.body
    Loop
    SendKeys "c:\baidu.htm"
    SendKeys "{ENTER}"
    WebBrowser1.ExecWB OLECMDID_SAVEAS, OLECMDEXECOPT_PROMPTUSER
    Kill tmpth
End Sub

在WebBrowser中发送POST请求的更多相关文章

  1. Vue中发送ajax请求——axios使用详解

    axios 基于 Promise 的 HTTP 请求客户端,可同时在浏览器和 node.js 中使用 功能特性 在浏览器中发送 XMLHttpRequests 请求 在 node.js 中发送 htt ...

  2. 如何在WinForm中发送HTTP请求

    如何在WinForm中请求发送HTTP 手工发送HTTP请求主要是调用 System.Net的HttpWebResponse方法 手工发送HTTP的GET请 求: string strURL = &q ...

  3. iOS中发送HTTP请求的方案

    在iOS中,常见的发送HTTP请求的方案有 苹果原生(自带) NSURLConnection:用法简单,最古老最经典的一种方案 NSURLSession:功能比NSURLConnection更加强大, ...

  4. golang中发送http请求的几种常见情况

    整理一下golang中各种http的发送方式 方式一 使用http.Newrequest 先生成http.client -> 再生成 http.request -> 之后提交请求:clie ...

  5. rails中发送ajax请求

    最近在写一个blog系统练练手,遇到一个一个问题,用户添加评论的时候想发送ajax请求,但是rails里的ajax和Python中的不太一样,Python中的ajax是用js,jquery实现的和ra ...

  6. IE6—在链接click事件的响应函数中发送jsonp请求不生效

    $("#link").click(function(){     $.ajax({         type: 'GET',         dataType: 'jsonp', ...

  7. java中发送http请求的方法

    package org.jeecgframework.test.demo; import java.io.BufferedReader; import java.io.FileOutputStream ...

  8. python中发送post请求时,报错“Unrecognized token 'xxxx': was expecting ('true', 'false' or 'null')”

    解决办法: 如请求参数为 data={“user”=“aaa”,“pwd”=“123456”,sign=“00000000000000”} 需要将参数data先做处理,调用函数datas=datajs ...

  9. Js/Ajax中发送HttpPost请求调用WebService

    1) WebService中的方法 [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(Confo ...

随机推荐

  1. gruntjs开发实例

    Grunt是基于Node.js的项目构建工具.它可以自动运行你所设定的任务,如编译less,sass,压缩js,合拼文件等等. (一)安装nodejs环境,Grunt 0.4.x要求Node.js的版 ...

  2. prim和kruskal比较

    推荐:http://squirrelrao.iteye.com/blog/1044867  http://www.cnblogs.com/xwdreamer/archive/2011/06/16/22 ...

  3. MIPS 汇编指令学习

    MIPS 寄存器 MIPS comes with 32 general purpose registers named $0. . . $31Registers also have symbolic ...

  4. tensorflow :ckpt模型转换为pytorch : hdf5模型

    参考链接:https://github.com/bermanmaxim/jaccardSegment/blob/master/ckpt_to_dd.py import tensorflow as tf ...

  5. spring-security-4 (3)spring security过滤器的创建与注册原理

    spring security是通过一个过滤器链来保护你的web应用安全.在spring security中,该过滤链的名称为springSecurityFilterChain,类型为FilterCh ...

  6. 6-11 Level-order Traversal(25 分)

    Write a routine to list out the nodes of a binary tree in "level-order". List the root, th ...

  7. [Luogu4899][IOI2018] werewolf 狼人

    luogu sol \(\mbox{IOI2018}\)的出题人有没有看过\(\mbox{NOI2018}\)的题目呀... \(\mbox{Kruskal}\)重构树+二维数点. 题目相当于是问你从 ...

  8. Linux和Docker常用命令

    一.常用Linux 命令 ls -a(同时列出隐含文件), -l(输出一个比较完整的格式,除每个文件名外,增加显示文件 类型.权限.硬链接数.所有者名.组名.大小(byte).及时间信息-----简化 ...

  9. 扩展ScriptBundle,支持混淆加密javascript

    一.需求: 在web开发中,经常会处理javascript的一些问题,其中就包括js的压缩,合并,发布版本以及混淆加密等等问题.在asp.net 开发中我们使用ScriptBundle已经可以解决ja ...

  10. bootstrap class sr-only 什么意思?

    bootstrap class sr-only 什么意思? 在看 bootstrap 内联表单时,label 有一个 class 是 sr-only. sr-only 是给屏幕阅读器用的,是给视力不方 ...