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