1
我有这个代码是为了做一个异步调用,但它不是,请看看它,让我知道哪里出了问题。异步HttpWebRequest不起作用
try
{
byte[] bytes;
Stream objRequestStream = null;
bytes = System.Text.Encoding.ASCII.GetBytes(GetJSONforGetMenuDetails(Id, MenuIds));
wReq = (HttpWebRequest)WebRequest.Create(new Uri("http://" + MobileWLCUrl + urlCreateCacheAPI));
wReq.ContentLength = bytes.Length;
wReq.ContentType = "text/x-json";
wReq.ServicePoint.Expect100Continue = false;
wReq.Method = "POST";
objRequestStream = wReq.GetRequestStream();
objRequestStream.Write(bytes, 0, bytes.Length);
objRequestStream.Close();
wReq.BeginGetResponse(new AsyncCallback(FinishWebRequest), null);
//resp = WebAccess.GetWebClient().UploadString("http://" + MobileWLCUrl + urlCreateCacheAPI, GetJSONforGetMenuDetails(Id, MenuIds));
//EngineException.CreateLog("Cache Created (for Menus: " + MenuIds + ") in API for LocationId: " + Id);
}
catch (Exception ex) { EngineException.HandleException(ex); }
void FinishWebRequest(IAsyncResult result)
{
WebResponse wResp = wReq.EndGetResponse(result) as WebResponse;
StreamReader sr = new StreamReader(wResp.GetResponseStream());
String res = sr.ReadToEnd();
EngineException.CreateLog("Cache Created (for Menus: " + MenuIds + ") in API for LocationId: " + LocId);
}
哪里出问题了?当我调试它时,它会等待电话继续下去,但这不应该发生。
那么可以做些什么:o – 1Mayur