2012-04-24 3 views
3

다음 코드를 사용하여 HTTP 게시를하고 있습니다. 이것은 대부분의 경우에 잘 작동하지만 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(); 
+1

byteArray.Length 란 무엇입니까? 요청 스트림에 쓰기 전에 올바른 데이터를 가지고 있습니까? – dash

+4

'''json'' 매개 변수가 urlencoded되어야한다는 것을 제외하고는 코드가 괜찮습니다. 데이터의 모양에 따라 문제가 될 수 있습니다. –

+0

어떤 웹 서버입니까? IIS가 serverfault.com에 가서 IIS 구성에 대해 물어보십시오. IIRC에는 urlscan.ini (IIS6) 또는 게시 된 데이터의 크기를 제한하는 메타베이스의 기본 설정이 있습니다. – james

답변

2

그 Uri.EscapeDataString (json)이 트릭을 수행했습니다.