我已经尝试过,但是不知道如何从API响应中读取数据。我可以获取200个状态代码,但无法弄清楚如何获取实际数据。我正在尝试从Withings API(http://developer.withings.com/oauth2/#tag/measure%2Fpaths%2Fhttps%3A~1~1wbsapi.withings.net~1measure%3Faction%3Dgetmeas%2Fget)中获取数据
我得到以下回应:
状态码:200,原因短语:“确定”,版本:1.1,内容:System.Net.Http.StreamContent,标头:{Access-Control-Allow-Origin:* Access-Control-Allow-Methods:GET,POST ,选项Access-Control-Allow-Headers:Content-Type,* Date:Mon,10 Jun 2019 11:51:03 GMT Server:Apache Content-Length:65 Content-Type:text / plain; charset = UTF-8
以下是我的代码:
string accessToken = "my_accessToken";
HttpClient client = new HttpClient();
var url = "https://wbsapi.withings.net/measure?action=getmeas&meastype=1&category=1&startdate=737060&enddate=737179&offset=0";
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + accessToken);
var response = await client.GetAsync(url);
string content1 = await response.Content.ReadAsStringAsync();
string content2 = response.Content.ReadAsStringAsync().Result;
上面我添加了withings API的链接。有谁指导如何从响应正文中获取数据。
答案 0 :(得分:0)
问题现在已解决。问题是API不支持TLS1,并且由于我将安全协议设置为Tls12,因此可以正常工作。下面是我使用的代码。
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
感谢所有人。