在 windows 上发布 restsharp cod 程序时没有任何反应
There is no response when i publish the restsharp cod program on windows
我有使用 RestSharp 和 Newtonsoft.Json 软件包登录的代码。这段代码是这样的:
Dim client = New RestClient("https://api.mysite.com/auth/login")
Dim request = New RestRequest(Method.POST)
request.AddHeader("authentication-key", "123")
request.AddHeader("authentication-id", "123")
request.AddParameter("application/x-www-form-urlencoded", "username=123&password=123", ParameterType.RequestBody)
Dim response As RestResponse = client.Execute(request)
MsgBox(response.Content.ToString)
If response.StatusCode.ToString = "OK" Then
'Save token
Dim result = JsonConvert.DeserializeObject(response.Content.ToString)
End If
当我 运行 这段代码在 Visual Studio 时,它起作用了。但是当我为 windows 发布它时, MsgBox 中没有响应。当我 运行 在我的计算机上发布程序(安装 visual studio )时,它可以工作并显示服务器的响应,但是当我 运行 在其他计算机上发布代码时,响应为空。请帮我 。
2天后终于解决了这个问题。此错误有两个原因。
1- 在源代码中将application/x-www-form-urlencoded
更改为application/json
。
2- 在用户计算机中使用 .NetFamework 版本 4.7.2。
我有使用 RestSharp 和 Newtonsoft.Json 软件包登录的代码。这段代码是这样的:
Dim client = New RestClient("https://api.mysite.com/auth/login")
Dim request = New RestRequest(Method.POST)
request.AddHeader("authentication-key", "123")
request.AddHeader("authentication-id", "123")
request.AddParameter("application/x-www-form-urlencoded", "username=123&password=123", ParameterType.RequestBody)
Dim response As RestResponse = client.Execute(request)
MsgBox(response.Content.ToString)
If response.StatusCode.ToString = "OK" Then
'Save token
Dim result = JsonConvert.DeserializeObject(response.Content.ToString)
End If
当我 运行 这段代码在 Visual Studio 时,它起作用了。但是当我为 windows 发布它时, MsgBox 中没有响应。当我 运行 在我的计算机上发布程序(安装 visual studio )时,它可以工作并显示服务器的响应,但是当我 运行 在其他计算机上发布代码时,响应为空。请帮我 。
2天后终于解决了这个问题。此错误有两个原因。
1- 在源代码中将application/x-www-form-urlencoded
更改为application/json
。
2- 在用户计算机中使用 .NetFamework 版本 4.7.2。