【发布时间】:2020-05-31 02:54:31
【问题描述】:
我可以通过这个网址进入我的浏览器并获取服务器时间,https://api.binance.je/api/v3/time
但我无法使用以下代码获得响应。我该如何调试这个
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();
}
}
}
【问题讨论】:
-
我得到
serverTime 1581787122886作为输出。你在看什么? -
这是完美的工作。
responseFromServer具有从 api 接收到的响应 json -
@as.if.i.code 我收到超时异常。如果它对你有用,也许还有其他问题,虽然我应该得到一些响应错误,因为它可以从我的网络浏览器工作
-
@Clint 我遇到了超时异常。如果它对你有用,也许有一个 ip 块或其他东西,虽然我应该得到一些响应错误
-
好的,它现在正在工作,我唯一要做的就是重新启动我的 VPN,它没有活动连接并且它正在工作:/