我在网站上写了一个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
答案 0 :(得分:0)
尝试将PHP
来源更改为:
<?php echo 'OK';
那应该删除空间。任何以PHP代码结尾的PHP文件都不应该有一个结束?>
,因为它只会导致恼人的问题。