public void AsyUpLoad(string url, byte[] bytes, string userId) { strBoundary = "----------" + DateTime.Now.Ticks.ToString("x"); boundaryBytes = Encoding.ASCII.GetBytes("\r\n--" + strBoundary + "\r\n"); var webState = new WebState(); try { var strPostHeader = string.Format(headerTemplate, strBoundary, "file", "temp"); var postHeaderBytes = Encoding.UTF8.GetBytes(strPostHeader); webState.WriteMemory(bytes, bytes.Length); webState.CreateRequest(url + "?file_path=" + userId); webState.SetRequestInfo("POST", false, 300000, "multipart/form-data; boundary=" + strBoundary, true, webState.GetMemorySize() + postHeaderBytes.Length + boundaryBytes.Length); m_size = webState.GetMemorySize(); m_curSize = 0; webState.SetStream(false); webState.SetBuffer(postHeaderBytes); webState.StreamBeginWrite(postHeaderBytes.Length, UpLoadWriteDataCallback); } catch (WebException e) { HttpHelperErr(string.Format(UpLoadErrFormat, webState.GetRequestUrl(), e.Message, e.Status), data); } }
public void AsyDownLoad(string url, string saveFilePath) { try { WebState webState = new WebState(saveFilePath); webState.CreateRequest(url); webState.BeginGetResponse(ResponseCallback); } catch (WebException e) { HttpHelperErr(string.Format(DownLoadErrFormat, url, e.Message, e.Status), data); } }