簡體   English   中英

如何使用HTTPclient Get方法從響應體讀取數據?

[英]How to read data from response body with HTTPclient Get method?

我試過但不知道如何從API響應中讀取數據。 我能夠獲得200狀態代碼,但我無法弄清楚如何獲得actualdata。 我試圖從Withings API獲取數據( http://developer.withings.com/oauth2/#tag/measure%2Fpaths%2Fhttps%3A~1~1wbsapi.withings.net~1measure%3Faction%3Dgetmeas%2Fget

以下回復我得到:

StatusCode:200,ReasonPhrase:'OK',版本:1.1,內容:System.Net.Http.StreamContent,標題:{Access-Control-Allow-Origin:* Access-Control-Allow-Methods:GET,POST,OPTIONS Access -Control-Allow-Headers:Content-Type,* Date:Mon,10 Jun 2019 11:51:03 GMT Server:Apache Content-Length:65 Content-Type:text / plain; 字符集= 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;

上面我添加了forings API的鏈接。 是否有人指導如何從響應正文中獲取數據。

問題現在已經解決了。 問題是API不支持TLS1,因為我將安全協議設置為Tls12,它的工作原理。 下面是我使用的代碼。

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

謝謝大家。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM