2012-12-13 160 views
3

我試圖發送一個請求的原始數據,並做了一些研究,發現Page.Request.InputStream想要我需要,但是當我進入我的頁面時,它總是空的。Request.InputStream始終爲空

我是新來的這個概念,因爲我來自Windows窗體應用程序在C#中。

這是我的網頁,我加載:

public override void process(NameValueCollection parametersReceived) 
    { 
     string urlDestination = ""; 
     urlDestination = parametersReceived[Includes.SUPPLIER_URL]; 

     Stream str; String strSoapMessage = ""; 
     Int32 strLen, strRead; 

     str = Request.InputStream; 

     strLen = Convert.ToInt32(str.Length); 

     byte[] strArr = new byte[strLen]; 

     strRead = str.Read(strArr, 0, strLen); 

     for (int i = 0; i < strLen; i++) 
     { 
      if (strSoapMessage.Length > 0) 
       strSoapMessage += "&"; 
      strSoapMessage += strArr[i].ToString(); 
     } 

     saveMyLog("DATA COMMUNICATION: \n Destination: " + urlDestination + "\n Request: " + strSoapMessage); 


     HttpWebRequest webRequest = null; 

     webRequest = (HttpWebRequest)WebRequest.Create(new Uri(urlDestination)); 
     webRequest.Method = "POST"; 
     webRequest.ContentType = "text/xml"; 
     webRequest.Headers.Add("SOAPAction", urlDestination); 

     using (StreamWriter requestStream = new StreamWriter(webRequest.GetRequestStream())) 
     { 
      requestStream.Write(strSoapMessage); 
     } 


     strSoapMessage = ""; 
     strSoapMessage = new StreamReader(webRequest.GetResponse().GetResponseStream()).ReadToEnd(); 

     Response.Write(strSoapMessage); 
     saveMyLog("\n Status: " + ((HttpWebResponse)webRequest.GetResponse()).StatusCode.ToString() + "\n Response: " + strSoapMessage); 

} 

謝謝!

回答

5

也許有人已經讀過InputStream並將其移動到最後?嘗試閱讀之前重置在開始位置:

Request.InputStream.Position = 0; 
// now read from the stream 
byte[] data = new byte[Request.InputStream.Length]; 
Request.InputStream.Read(data, 0, data.Length); 
+0

我已經tryed這一點,如果我暫停breake只是befor我打開我的網頁看看Request.InputStream好說0 – XandrUu

+0

好沒有工作,在這種情況下,您可能會想要顯示您的代碼:客戶端和服務器。 –

+0

我更新了問題 – XandrUu