Foxtable(狐表)用户栏目专家坐堂 → [求助]怎么把json数据post出去


  共有1916人关注过本帖树形打印复制链接

主题:[求助]怎么把json数据post出去

帅哥哟,离线,有人找我吗?
浙江仔
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1316 积分:9484 威望:0 精华:1 注册:2010/7/21 14:20:00
[求助]怎么把json数据post出去  发帖心情 Post By:2019/5/16 10:52:00 [只看该作者]

一查询网页中的数据提交js如下,该怎么写post代码?
    function doSearch() {
        $("#certList").html("查询中");
        $.ajax({
            url: "/examweb/api/v2/certificate/query_json.xhtml",
            dataType: "json",
            type: "POST",
            data: {
                "username": $("#studentName").val(),
                "idcard": $("#studentCardId").val(),
                _: (new Date() - 0)
            },
            error: function (data) {
                $("#certList").html("当前服务器响应可能有问题,请几分钟后再试!");
            },
            success: function (data) {
                var html = '';
                console.log(data);
                if (data.status == 'success' && data.data != null && data.data.length > 0) {
                    var render = template.compile("succView", $("#succView").html());
                    html = render(data);
                } else {
                    html = "对不起,查无结果";
                }
                $("#certList").html(html);
            }
        });
    }

 回到顶部
帅哥哟,离线,有人找我吗?
浙江仔
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1316 积分:9484 威望:0 精华:1 注册:2010/7/21 14:20:00
  发帖心情 Post By:2019/5/16 11:47:00 [只看该作者]

查询网址是:

 

https://zscx.zjsafety.gov.cn/examweb/certList.jsp

 

 

之前是按照下面的方式写的,现在有post数据提交,想改,不知道怎么把json数据传出去

 

Dim name As String=Functions.Execute("utf8",e.Form.controls("TextBox1").text)

Dim id As String=e.Form.controls("TextBox2").text

 

Dim time As String =DateDiff("s", "01/01/1970 00:00:00", Now())

Dim msg As String = "username=" & name &"&idcard=" & id & "&_=" & time

Dim req = System.Net.WebRequest.Create("http://zscx.zjsafety.gov.cn/examweb/api/v2/certificate/query_json.xhtml")

req.Method = "POST"

req.Timeout = 5000

req.C

Dim aryBuf As Byte() = Encoding.GetEncoding("GB2312").GetBytes(msg)

req.ContentLength = aryBuf.Length

Dim writer = req.GetRequestStream()

writer.Write(aryBuf, 0, aryBuf.Length)

writer.Close()

writer.Dispose()

Dim pos = req.GetResponse

Dim stm As System.IO.Stream = pos.GetResponseStream()

Dim reader As New System.IO.StreamReader(stm)

Dim str As String = reader.ReadToEnd

pos.Close

stm.Close

reader.close

 


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2019/5/16 12:50:00 [只看该作者]

Dim name As String="张三"
Dim id As String="abc"
Dim time As String =DateDiff("s", new Date(1970, 1, 1), Now())
Dim msg As String = "username=" & name &"&idcard=" & id & "&_=" & time
msgbox(msg)
Dim req = System.Net.WebRequest.Create("https://zscx.zjsafety.gov.cn/examweb/api/v2/certificate/query_json.xhtml")
req.Method = "POST"
req.Timeout = 5000
req.ContentType = "application/x-www-form-urlencoded; charset=UTF-8"
req.UserAgent = "Mozilla/5.0 (Windows NT 6.3; rv:66.0) Gecko/20100101 Firefox/66.0"
Dim aryBuf As Byte() = Encoding.GetEncoding("utf-8").GetBytes(msg)
req.ContentLength = aryBuf.Length
Dim writer = req.GetRequestStream()
writer.Write(aryBuf, 0, aryBuf.Length)
writer.Close()
writer.Dispose()
Dim pos = req.GetResponse
Dim stm As System.IO.Stream = pos.GetResponseStream()
Dim reader As New System.IO.StreamReader(stm)
Dim str As String = reader.ReadToEnd
pos.Close
stm.Close
reader.close

msgbox(str)


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2019/5/16 12:54:00 [只看该作者]

Dim name As String="张三"
Dim id As String="abc"
Dim hc As New HttpClient("https://zscx.zjsafety.gov.cn/examweb/api/v2/certificate/query_json.xhtml")
hc.contentType = "application/x-www-form-urlencoded; charset=UTF-8"
hc.Timeout = 5 '设置超时为5秒
Dim time As String =DateDiff("s", new Date(1970, 1, 1), Now())
Dim msg As String = "username=" & name &"&idcard=" & id & "&_=" & time
hc.Content = msg
Dim ret As String = hc.GetData()
MessageBox.Show(ret)
[此贴子已经被作者于2019/5/16 12:54:10编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
浙江仔
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1316 积分:9484 威望:0 精华:1 注册:2010/7/21 14:20:00
  发帖心情 Post By:2019/5/16 13:56:00 [只看该作者]

太感谢了

 回到顶部