代码之家  ›  专栏  ›  技术社区  ›  hosein noori

在windows上发布restsharp cod程序时没有响应

  •  1
  • hosein noori  · 技术社区  · 6 年前

    我有一个使用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)中运行已发布的程序时,它可以工作并显示服务器的响应,但当我在其他计算机中运行已发布的代码时,响应为null。请帮帮我。

    1 回复  |  直到 6 年前
        1
  •  0
  •   hosein noori    6 年前

    两天后,我终于可以解决这个问题了。Tere是导致此错误的两个原因。

    1.改变 application/x-www-form-urlencoded application/json 在源代码中。

    2-使用。用户计算机中的NetFamework 4.7.2版。