-2

PHP在网站上写了一个页面来回应OK。在PHP中,这是通过以下方式完成的:

echo 'OK';

当我请求页面.NET并将响应读入字符串时,生成的字符串有一个尾随空格,所以它是'OK '. 字符串的长度为 3 个字符。为什么会这样,我该如何解决?

.NET代码是:

Private Function GetStrFromPostRequest(ByVal url As String, ByVal encoding As Text.Encoding, ByVal params As String) As String

    Dim strWebResponse As String
    Dim Request As HttpWebRequest = WebRequest.Create(url)
    Request.Method = "POST"
    Request.ContentType = "application/x-www-form-urlencoded"
    Using writer As StreamWriter = New StreamWriter(Request.GetRequestStream(), encoding)
        writer.Write(params)
    End Using
    Using Response As WebResponse = Request.GetResponse
        Using reader As StreamReader = New StreamReader(Response.GetResponseStream(), encoding)
            strWebResponse = reader.ReadToEnd
        End Using
    End Using

    Return strWebResponse

End Function
4

1 回答 1

0

尝试将您的PHP来源更改为:

<?php echo 'OK';

那应该删除空间。任何以 PHP 代码结尾的 PHP 文件都不应该有结束符?>,因为它只会导致烦人的问题。

于 2012-11-12T09:51:53.527 回答