Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# HttpException请求超时_C#_Asp.net_.net - Fatal编程技术网

C# HttpException请求超时

C# HttpException请求超时,c#,asp.net,.net,C#,Asp.net,.net,我可以通过此url进入我的浏览器并获取服务器时间 但我无法使用下面的代码获得响应。我如何调试这个 using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program {

我可以通过此url进入我的浏览器并获取服务器时间

但我无法使用下面的代码获得响应。我如何调试这个

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a request for the URL.        
            WebRequest request = WebRequest.Create("https://api.binance.je/api/v3/time");
            // If required by the server, set the credentials.
            request.Credentials = CredentialCache.DefaultCredentials;
            // Get the response.
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            // Display the status.
            Console.WriteLine(response.StatusDescription);
            // Get the stream containing content returned by the server.
            Stream dataStream = response.GetResponseStream();
            // Open the stream using a StreamReader for easy access.
            StreamReader reader = new StreamReader(dataStream);
            // Read the content.
            string responseFromServer = reader.ReadToEnd();
            // Display the content.
            Console.WriteLine(responseFromServer);
            // Cleanup the streams and the response.
            reader.Close();
            dataStream.Close();
            response.Close();
        }
    }
}

我看到您可以从网站检索json数据。在我这方面进行了测试。 但是,如果您仅尝试获取值,则需要读取json字符串(responsefromServer)。这可以通过使用名为Newtonsoft的nuget包来实现。 然后,您必须将以下内容添加到代码中

名称空间上方:

using Newtonsoft.Json.Linq;
在关闭读卡器enz之前的主功能中:

        //Create jsonObject object from the api call response
        JObject jObject = JObject.Parse(responseFromServer);
        //Read propertie called serverTime and convert this to string to match variabele set
        string time = jObject["serverTime"].ToString();
        //Write the given time
        Console.WriteLine(time);
您的代码如下所示:

using Newtonsoft.Json.Linq;
using System;
using System.IO;
using System.Net;

namespace StackOverflow
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            // Create a request for the URL.        
            WebRequest request = WebRequest.Create("https://api.binance.je/api/v3/time");
            // If required by the server, set the credentials.
            request.Credentials = CredentialCache.DefaultCredentials;
            // Get the response.
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            // Display the status.
            Console.WriteLine(response.StatusDescription);
            // Get the stream containing content returned by the server.
            Stream dataStream = response.GetResponseStream();
            // Open the stream using a StreamReader for easy access.
            StreamReader reader = new StreamReader(dataStream);
            // Read the content.
            string responseFromServer = reader.ReadToEnd();
            // Display the content.
            Console.WriteLine(responseFromServer);


            //Create jsonObject object from the api call response
            JObject jObject = JObject.Parse(responseFromServer);
            //Read propertie called serverTime and convert this to string to match variabele set
            string time = jObject["serverTime"].ToString();
            //Write the given time
            Console.WriteLine(time);


            // Cleanup the streams and the response.
            reader.Close();
            dataStream.Close();
            response.Close();
        }
    }
}

我看到您可以从网站检索json数据。在我这方面进行了测试。 但是,如果您仅尝试获取值,则需要读取json字符串(responsefromServer)。这可以通过使用名为Newtonsoft的nuget包来实现。 然后,您必须将以下内容添加到代码中

名称空间上方:

using Newtonsoft.Json.Linq;
在关闭读卡器enz之前的主功能中:

        //Create jsonObject object from the api call response
        JObject jObject = JObject.Parse(responseFromServer);
        //Read propertie called serverTime and convert this to string to match variabele set
        string time = jObject["serverTime"].ToString();
        //Write the given time
        Console.WriteLine(time);
您的代码如下所示:

using Newtonsoft.Json.Linq;
using System;
using System.IO;
using System.Net;

namespace StackOverflow
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            // Create a request for the URL.        
            WebRequest request = WebRequest.Create("https://api.binance.je/api/v3/time");
            // If required by the server, set the credentials.
            request.Credentials = CredentialCache.DefaultCredentials;
            // Get the response.
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            // Display the status.
            Console.WriteLine(response.StatusDescription);
            // Get the stream containing content returned by the server.
            Stream dataStream = response.GetResponseStream();
            // Open the stream using a StreamReader for easy access.
            StreamReader reader = new StreamReader(dataStream);
            // Read the content.
            string responseFromServer = reader.ReadToEnd();
            // Display the content.
            Console.WriteLine(responseFromServer);


            //Create jsonObject object from the api call response
            JObject jObject = JObject.Parse(responseFromServer);
            //Read propertie called serverTime and convert this to string to match variabele set
            string time = jObject["serverTime"].ToString();
            //Write the given time
            Console.WriteLine(time);


            // Cleanup the streams and the response.
            reader.Close();
            dataStream.Close();
            response.Close();
        }
    }
}

问题出在我的vpn上。即使我没有积极的联系。我关闭了后台服务并重新启动它,现在正在工作

类似问题
问题出在我的vpn上。即使我没有积极的联系。我关闭了后台服务并重新启动它,现在正在工作

类似问题

我得到了
服务器时间1581787122886
作为输出。你看到了什么?这很好用
responseFromServer
具有从接收到的响应jsonapi@as.if.i.code我收到一个超时异常。如果它对你有效,也许还有其他问题,尽管我应该在我的网络上得到一些响应错误broswer@Clint我收到一个超时异常。如果它对您有效,可能存在ip块或其他问题,尽管我应该得到一些响应错误OK它现在正在工作,我唯一做的事情是重新启动没有活动连接的VPN,并且它正在工作,因此:/i获得
serverTime 1581787122886
作为输出。你看到了什么?这很好用
responseFromServer
具有从接收到的响应jsonapi@as.if.i.code我收到一个超时异常。如果它对你有效,也许还有其他问题,尽管我应该在我的网络上得到一些响应错误broswer@Clint我收到一个超时异常。如果它对您有效,可能是ip阻塞或其他原因,虽然我应该得到一些响应错误OK它现在正在工作,我唯一做的事情是重新启动没有活动连接的VPN,并且它正在工作,因此:/我没有得到任何响应,可能是其他问题我的sideOk它正在工作,我所做的唯一一件事就是重新启动我的VPN,因为它没有活动连接,并且正在工作,所以:/啊,oke不知道你在哪里使用VPN。很高兴它现在起作用了!快乐编码!奇怪的是,我说vpn没有激活,但我重新启动了服务,并确认它工作正常。该用户在这里遇到了完全相同的问题感谢您的帮助无论如何都德,我没有得到任何响应可能还有其他问题我的sideOk它正在工作,我所做的唯一一件事就是重新启动我的VPN,它没有活动连接,并且正在工作,因此:/啊,oke不知道您在哪里使用VPN。很高兴它现在起作用了!快乐编码!奇怪的是,我说vpn没有激活,但我重新启动了服务,并确认它工作正常。这个用户也有同样的问题谢谢你的帮助伙计