VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > VB.net教程 >
  • vb.net 接口POST方式传参数提交返回值

 

	
  1. Try
  2.  
    Dim WebClientObj As New System.Net.WebClient()
  3.  
    Dim PostVars As New System.Collections.Specialized.NameValueCollection()
  4.  
    'URL
  5.  
    Dim url1 As String = "http://ip地址/sso/rest/user/create.json"
  6.  
    '参数一:requestTime 时间差
  7.  
    Dim requestTime As String = CLng((DateTime.UtcNow - Jan1st1970).TotalMilliseconds).ToString()
  8.  
    '参数二:content。要用双引号拼接 <span style="font-family: Arial, Helvetica, sans-serif;">Chr(34) 双引号的意思</span>
  9.  
    Dim content1 As String = "{'fullName': '名字','name': '名字','sn': '名字','givenName': '名字','displayName': '名字','mail': 'sdfsadgsd@fubon.com.cn','unicodePwd': '111'}"
  10.  
    '参数三:sign
  11.  
    Dim sign As String = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(content2, "MD5")
  12.  
    ''参数四:Authorization
  13.  
    Dim base1 As String = "Basic WldsdzpVMkZzZEdWa1gxK0NzQzZXWHNZRHN0eEllcndMN1lkTExoWC83ZTZ6dGt3PQ=="
  14.  
    PostVars.Add("requestTime", requestTime)
  15.  
    PostVars.Add("content", content1)
  16.  
    PostVars.Add("sign", sign)
  17.  
    Try
  18.  
    '设置Headers
  19.  
    WebClientObj.Headers.Add("Authorization", base1)
  20.  
    '请求URL和参数
  21.  
    Dim byRemoteInfo As Byte() = WebClientObj.UploadValues(url1, "POST", PostVars)
  22.  
    '获取返回信息
  23.  
    Dim sRemoteInfo As String = System.Text.Encoding.[Default].GetString(byRemoteInfo)
  24.  
    '这是获取返回信息
  25.  
    Dim str5 As String = sRemoteInfo
  26.  
    Catch
  27.  
    End Try
  28.  
    Catch ex As Exception
  29.  
    End Try
 



相关教程