您好,欢迎来到东饰资讯网。
搜索
您的当前位置:首页vb.net post服务器文件,使用VB.Net发送Post请求

vb.net post服务器文件,使用VB.Net发送Post请求

来源:东饰资讯网

我想从服务器端发送Post请求到另一台服务器。我想在代码中创建一些表单数据(不使用网页)并发送。使用VB.Net发送Post请求

从我在线阅读我已经结束了下面的代码。然而,我只是在猜测,并不确定它是否正确,特别是因为我无法使它正常工作(我得到的例外已包含在代码中的注释中)。这是我的错,还是与我发送请求的地方有关的外部问题?

Dim client = New HttpClient

Dim request = WebRequest.CreateHttp("https://something.com/test")

request.Credentials = CredentialCache.DefaultCredentials

request.UserAgent = "value"

request.Method = HttpMethod.Post.Method

request.ContentType = "application/x-www-form-urlencoded"

Dim params = New Dictionary(Of String, String)

params.Add("key1", "value1")

params.Add("key2", "value2")

params.Add("key3", "value3")

params.Add("key4", "value4")

Dim stream = request.GetRequestStream()

Dim content = New FormUrlEncodedContent(params)

content.CopyToAsync(stream)

' Exception occurs when executing the line below:

' The underlying connection was closed: An unexpected error occurred on a send.

' InnerException = {"Unable to read data from the transport connection:

' An existing connection was forcibly closed by the remote host."}

Dim result = request.GetResponseAsync().Result

Console.WriteLine(result.ToString)

2017-05-30

Mayron

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- huatuoyibo.cn 版权所有 湘ICP备2023022426号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务