猿问

异步调用接口为什么没有弹出数据来?

     string url = string.Format("http://www.csdn.net");

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            request.Method = "psot";

            request.Accept = "*/*";

            request.UserAgent = "Mozilla/5.0";

            request.ContentType = "application/x-www-form-urlencoded";

            request.KeepAlive = false;


            using (Stream stream = request.GetRequestStream())

            {

                string sendMsg = string.Empty;

                byte[] buffer = new byte[url.Length];

                stream.BeginWrite(buffer, 0, buffer.Length, new AsyncCallback(SearchBeginWrite), stream);


            }

            request.BeginGetResponse(new AsyncCallback(SearchBeginResponse), request);

        }

        //异步发送请求回调函数

        private void SearchBeginWrite(IAsyncResult writeResult)

        {

            Stream stream = (Stream)writeResult.AsyncState;

            stream.EndWrite(writeResult);

            stream.Close();

        }

        private void SearchBeginResponse(IAsyncResult ResponseResult)

        {

            HttpWebRequest request = (HttpWebRequest)ResponseResult.AsyncState;

            HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(ResponseResult);

            Stream stream = response.GetResponseStream();

            StreamReader sr = new StreamReader(stream);

            string msg = sr.ReadToEnd();

            JObject jo = JObject.Parse(msg);

            string[] values = jo.Properties().Select(item => item.Value.ToString()).ToArray();

求问这个异步调用接口的代码哪里错了,为什么没有数据弹窗啊?我调试的时候每行代码都有走啊


尼古拉斯凯奇狗蛋
浏览 1167回答 1
1回答

习惯受伤

用事件去做
随时随地看视频慕课网APP
我要回答