c#WebRequest不会发布整个数据长度

I am currently having a problem. I am trying to post my data to a PHP document but it does not get the whole value. Somewhere in the middle it stops posting.

Does anyone know where the problem is located? The bytearray is 7401 long. That cant be to long rigth?

My code is below:

public string RecieveData(string url, string postData = "")
    {

            WebRequest request = WebRequest.Create(url);
            // If required by the server, set the credentials.

            NetworkCredential nc = new NetworkCredential("user", "pass");
            Stream dataStream;  

            if (postData != "")
            {
                // Set the Method property of the request to POST.
                request.Method = "POST";
                // Create POST data and convert it to a byte array.string postData = "This is a test that posts this string to a Web server.";
                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.
                dataStream = request.GetRequestStream();
                // Write the data to the request stream.
                dataStream.Write(byteArray, 0, byteArray.Length);
                // Close the Stream object.
                dataStream.Close();
            }

            request.Credentials = nc;
            // Get the response.
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            // Display the status.
            Console.WriteLine(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. 
            string responseFromServer = reader.ReadToEnd();
            // Display the content.
            Console.WriteLine(responseFromServer);
            // Cleanup the streams and the response.
            reader.Close();
            dataStream.Close();
            response.Close();

            return responseFromServer;
        /*
        }
        catch (Exception)
        {
            MessageBox.Show("Er is iets fout gegaan met verbinden");
            return "";
        }
        */

    }
doushuhuai7247
doushuhuai7247 是什么让你认为它停止发布?您是否使用Wireshark或类似的东西来查看网络级别的情况?
接近 8 年之前 回复

1个回答



7401不会太长。</ p>

我的猜测是你发布的数据不是 完全URL编码,例如 字节数组中的一个字符会导致PhP解析器停止。 确保您正在查看原始数据(例如使用Wireshark)。</ p>
</ div>

展开原文

原文

7401 is not too long.

My guess is that the data you are posting are not fully URL-encoded, e.g. one of the characters in the byte array causes the PhP parser to stop. Make sure you are looking at the raw data (e.g. using Wireshark).

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问