这种情况发生在知缓以UTF-8编码格式传输数据的时候,这开头的三个字节叫做BOM(Byte Order Mark,字节顺序标记),小程序接收到php端返回的数据后租猛野,把开头的三个字节去掉即可。
更彻底的解决办法是把php文件保存为 不带BOM的UTF-8 文件,这样返回的数据就不带弊喊BOM了
string url= "xxx.php"HttpWebRequest hwr = (HttpWebRequest)HttpWebRequest.Create(uri)
hwr.Method = requestMethod.ToString()
hwr.KeepAlive = true
hwr.Timeout = 60 * 1000
hwr.ContentLength = byteArray.Length
using (Stream rqStream = hwr.GetRequestStream())
{
string requstData = "aa=bbb"
byte[] byteArray = Encoding.UTF8.GetBytes(requstData)
rqStream.Write(byteArray, 0, byteArray.Length)
rqStream.Dispose()
}
string resultStr =""
using (WebResponse resp = hwr.GetResponse())
{
Stream rpStream = resp.GetResponseStream()
StreamReader sr = new StreamReader(rpStream)
resultStr = sr.ReadToEnd()
rpStream.Dispose()
}
//返回字符串 处理 resultStr
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)