vb.net 介面POST方式傳引數提交返回值

chinaherolts2008發表於2021-01-04
Try
                                    Dim WebClientObj As New System.Net.WebClient()
                                    Dim PostVars As New System.Collections.Specialized.NameValueCollection()
                                    'URL
                                    Dim url1 As String = "http://ip地址/sso/rest/user/create.json"
                                    '引數一:requestTime 時間差
                                    Dim requestTime As String = CLng((DateTime.UtcNow - Jan1st1970).TotalMilliseconds).ToString()
                                    '引數二:content。要用雙引號拼接 <span style="font-family: Arial, Helvetica, sans-serif;">Chr(34) 雙引號的意思</span>
                                    Dim content1 As String = "{'fullName': '名字','name': '名字','sn': '名字','givenName': '名字','displayName': '名字','mail': 'sdfsadgsd@fubon.com.cn','unicodePwd': '111'}"
                                    '引數三:sign
                                    Dim sign As String = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(content2, "MD5")
                                    ''引數四:Authorization
                                    Dim base1 As String = "Basic WldsdzpVMkZzZEdWa1gxK0NzQzZXWHNZRHN0eEllcndMN1lkTExoWC83ZTZ6dGt3PQ=="
                                    PostVars.Add("requestTime", requestTime)
                                    PostVars.Add("content", content1)
                                    PostVars.Add("sign", sign)
                                    Try
                                        '設定Headers
                                        WebClientObj.Headers.Add("Authorization", base1)
                                        '請求URL和引數
                                        Dim byRemoteInfo As Byte() = WebClientObj.UploadValues(url1, "POST", PostVars)
                                        '獲取返回資訊
                                        Dim sRemoteInfo As String = System.Text.Encoding.[Default].GetString(byRemoteInfo)
                                        '這是獲取返回資訊
                                        Dim str5 As String = sRemoteInfo
                                    Catch
                                    End Try
                                Catch ex As Exception
                                End Try

vb.net教程c#教程python基礎教程

相關文章