gpt4 book ai didi

c# - 仅在第一个 http 请求中获得空响应 Windows Phone 8

转载 作者:塔克拉玛干 更新时间:2023-11-01 19:07:32 25 4
gpt4 key购买 nike

每当我在 Windows Phone 8 中启动应用程序并发送 http GET 请求时,我都会收到空响应。这只是第一个请求,对同一 url 的进一步请求的响应不是空的。

代码如下:

string res = "";

private void ReadUrlAsync(string url)
{
var request = HttpWebRequest.Create(new Uri(url)) as HttpWebRequest;
// request.Accept = "application/json;odata=verbose";
request.BeginGetResponse(ResponseCallback, request);
}

private void ResponseCallback(IAsyncResult asyncResult)
{
HttpWebRequest request = (HttpWebRequest)asyncResult.AsyncState;
HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asyncResult);
string data;
using (Stream responseStream = response.GetResponseStream())
{

using (var reader = new System.IO.StreamReader(responseStream))
{
data = reader.ReadToEnd();
}
}
res = data;
}

最佳答案

我使用了一些不同的代码并找到了解决方案:

        HttpClient cl = new HttpClient();
return await cl.GetStringAsync(new Uri(url));

关于c# - 仅在第一个 http 请求中获得空响应 Windows Phone 8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28994293/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com