我在网站上写了一个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文件都不应具有关闭的?>
,因为它只是引起烦人的问题。