• VB.NET GET接口传送数据,获取返回值


    先在引用里,右击添加引用。COM选项下找到Microsoft  WinHTTP  Service, version  5.1

    Imports System.Web
    Imports System.Text
    Imports System.IO
    Imports System.Net
    Imports WinHttp
    Imports System
    
    ''' <summary>
    ''' 微信接口帮助类 20160713
    ''' </summary>
    ''' <remarks></remarks>
    Public Class WeChatHelper
    
    
    #Region "微信推送接口"
        Public Shared Function ToPost(ByVal inputJson As inputJson) As String
    Dim url As String = "http://cp.tunnel.qydev.com/rest/eip/eipNotice?inputJson="
            'Dim strparam As String = "inputJson :{"
            Dim strparam As String = "{"
            strparam += Chr(34) & "fromUser" & Chr(34) & ":" & Chr(34) & "eip" & Chr(34) & ","
            strparam += Chr(34) & "toUser" & Chr(34) & ":" & Chr(34) & "fcps" & Chr(34) & ","
            strparam += Chr(34) & "transactionFormat" & Chr(34) & ":" & Chr(34) & "json" & Chr(34) & ","
            strparam += Chr(34) & "transactionId" & Chr(34) & ":" & Chr(34) & "" & Guid.NewGuid().ToString() & "" & Chr(34) & ","
            strparam += Chr(34) & "transactionType" & Chr(34) & ":" & Chr(34) & "40" & Chr(34) & ","
            strparam += Chr(34) & "room_id" & Chr(34) & ":" & Chr(34) & "100800" & Chr(34) & ","
            strparam += Chr(34) & "room_name" & Chr(34) & ":" & Chr(34) & "软件园公务车" & Chr(34) & ","
            strparam += Chr(34) & "Starpoint" & Chr(34) & ":" & Chr(34) & "北京" & Chr(34) & ","
            strparam += Chr(34) & "Endpoint" & Chr(34) & ":" & Chr(34) & "上海" & Chr(34) & ","
            strparam += Chr(34) & "begin_date" & Chr(34) & ":" & Chr(34) & "2015/6/13 02:05:20" & Chr(34) & ","
            strparam += Chr(34) & "end_date" & Chr(34) & ":" & Chr(34) & "2015/6/13 10:40:15" & Chr(34) & ","
            strparam += Chr(34) & "purpose" & Chr(34) & ":" & Chr(34) & "测试GET接口" & Chr(34) & ","
            strparam += Chr(34) & "employ_name" & Chr(34) & ":" & Chr(34) & "程序三科 沈文锋" & Chr(34) & ","
            strparam += Chr(34) & "tel" & Chr(34) & ":" & Chr(34) & "13888888888" & Chr(34) & ","
            strparam += Chr(34) & "flag" & Chr(34) & ":" & Chr(34) & "已审核" & Chr(34) & ","
            strparam += Chr(34) & "employ_driver_no" & Chr(34) & ":" & Chr(34) & "0002439" & Chr(34) & ""
            strparam += "}"
            Dim aa As String = GetResponse(url & strparam)
            Return aa
    
        End Function
    #End Region
    
    #Region "GET请求1"
        Private Shared aHttpRequest As WinHttp.WinHttpRequest
        Public Shared Function GetResponse(ByVal url As String) As String
            Dim strResult As String = ""
    
            Try
                Dim wrq As System.Net.WebRequest = System.Net.WebRequest.Create(url)
                wrq.Method = "GET"
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3
                Dim wrp As System.Net.WebResponse = wrq.GetResponse()
                Dim sr As New System.IO.StreamReader(wrp.GetResponseStream(), System.Text.Encoding.GetEncoding("UTF-8"))
                strResult = sr.ReadToEnd()
            Catch ex As Exception
                Return ex.Message
            End Try
    
            Return strResult
        End Function
    #End Region


  • 相关阅读:
    PostGIS解压版安装
    gulp监听文件变化,并拷贝到指定目录
    pre在火狐中不换行
    Undefined symbols for architecture i386: "_crc32", referenced from:
    响应式自动化开发流程-Windows 版
    Gulp入门教程
    SVG折线图
    git-版本控制
    log4j
    CSS:描述样式
  • 原文地址:https://www.cnblogs.com/wybshyy/p/16042689.html
Copyright © 2020-2023  润新知