我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