When executing the below code I am getting errors:
C#/VB.NET Code:
public void CallEvent(string runtimeParams)
{
try
{
Customer ThisCustomer = ((AspDotNetStorefrontPrincipal)HttpContext.Current.User).ThisCustomer;
if (this.CalloutURL.Trim() != "" && this.Active)
{
String str = AppLogic.RunXmlPackage(this.m_XmlPackage, null, ThisCustomer, 1, "", runtimeParams, false, false);
byte[] data = Encoding.UTF8.GetBytes(str);
HttpWebRequest webRequest = (HttpWebRequest)System.Net.WebRequest.Create(this.m_CalloutURL); //Webrequest must be fully qualified to avoid compile warnings in VB
webRequest.Credentials = CredentialCache.DefaultCredentials;
webRequest.Method = "POST";
webRequest.ContentLength = data.Length;
webRequest.ContentType = "application/x-www-form-urlencoded";
// For Async Call
// Create the state object.
ManualResetEvent WaitHndle = new ManualResetEvent(false);
RequestState rs = new RequestState(WaitHndle, this.Debug);
// Put the request into the state object so it can be passed around.
rs.Request = webRequest;
rs.DataToSend = data;
webRequest.BeginGetRequestStream(new AsyncCallback(ReadCallbackRequest), rs);
// Issue the async request
IAsyncResult r = (IAsyncResult)webRequest.BeginGetResponse(new AsyncCallback(AspdnsfEventHandler.RespCallback), rs);
ThreadPool.RegisterWaitForSingleObject(r.AsyncWaitHandle, new WaitOrTimerCallback(AspdnsfEventHandler.ScanTimeoutCallback), rs, (30 * 1000), true); //30 sec timeout
allDone.WaitOne();
rs.ResponseStream.Close();
}
}
catch (WebException ex) { string str = ex.ToString(); }
catch (Exception ex) { string sr = ex.ToString(); }
}
The errors I am getting are as follows:
You must write ContentLength bytes to the request stream before calling [Begin]GetResponse.
Can anybody help