3
我正在使用以下代碼來執行HTTP Post。這在大多數情況下工作正常,但切斷我的字符串在一定的長度約4300字符串字符。我怎樣才能解決這個問題?我有一種預感,認爲這與所有未發佈的數據相關,並且在發佈期間中斷。我怎樣才能解決這個問題?HTTP後切斷字符串
ASCIIEncoding encoding = new ASCIIEncoding();
// Create a request using a URL that can receive a post.
WebRequest request = WebRequest.Create("<URL>");
// Set the Method property of the request to POST.
request.Method = "POST";
// Create POST data and convert it to a byte array.
string postData = "json=" + json;
//string postData = "json=blah";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded";
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Get the request stream.
Stream dataStream = request.GetRequestStream();
// Write the data to the request stream.
dataStream.Write(byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close();
// Get the response.
WebResponse response = request.GetResponse();
// Display the status.
//Console.WriteLine(((HttpWebResponse)response).StatusDescription);
// Get the stream containing content returned by the server.
dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
retVal = reader.ReadToEnd();
// Clean up the streams.
reader.Close();
dataStream.Close();
response.Close();
什麼是byteArray.Length?在寫入請求流之前,您是否擁有正確的數據? – dash 2012-04-24 23:29:44
代碼對我來說看起來不錯,除了他'''json'''參數應該被urlencoded。根據數據的外觀,這可能是問題所在。 – 2012-04-24 23:30:17
什麼網頁服務器?如果IIS轉到serverfault.com並詢問IIS配置。 IIRC在urlscan.ini(IIS6)或元數據庫中存在默認設置,用於限制發佈數據的大小。 – james 2012-04-24 23:30:30