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



我当前有问题。我正在尝试将数据发布到PHP文档中,但没有获得全部值。中间的某个地方停止发布。

有人知道问题所在吗?Bytearray长7401。那不能是长时间的吗?

我的代码如下:

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 "";
        }
        */
    }

7401不长。

我的猜测是您发布的数据未完全编码,例如字节数组中的一个字符之一导致PHP解析器停止。确保您正在查看原始数据(例如使用Wireshark)。

相关内容

  • 没有找到相关文章

最新更新