为什么网页中的Webresponse具有尾随空间



我在网站上写了一个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

尝试将PHP源更改为:

<?php echo 'OK';

应该删除空间。任何以PHP代码结尾的PHP文件都不应具有关闭的?>,因为它只是引起烦人的问题。

相关内容

  • 没有找到相关文章

最新更新