0

私は現在問題を抱えています。データを 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 "";
        }
        */

    }
4

1 に答える 1

0

7401 は長すぎません。

私の推測では、投稿しているデータは完全に URL エンコードされていません。たとえば、バイト配列内の文字の 1 つが原因で PhP パーサーが停止します。生データを見ていることを確認してください (例: Wireshark を使用)。

于 2013-10-23T00:29:21.783 に答える