公司老项目需要写微信小程序支付,支付成功后需要接口回调,但是怎么写都取不到回调信息
Stream stream = HttpContext.Current.Request.InputStream;
stream.Position = 0;
StreamReader streamReader = new StreamReader(stream);
string data = streamReader.ReadToEnd();
贴上答案,百度一个个试了好久,最后发现就是缺了stream.Position = 0;这一行代码,没写这行的时候,在webapi里面也能取到请求流,但是我项目是网站里包的webservices,可能有这方面原因,加上这个就好了!
循环读取内容
StringBuilder builder = new StringBuilder();
while((flag=reqStream.Read(buffer,0,(int)reqStream.Length)>0)
{
builder.Append(Encoding.UTF8.GetString(buffer, 0, (int)reqStream.Length));
}
@码上有钱(why): 虽然这种方法试过了但是没有用,但还是感谢您的回答,三克油
@码上有钱(why): 玛德,万恶的博客园排版,结贴的时候分给错人了,淦
StringBuilder builder = new StringBuilder();
while((flag=reqStream.Read(buffer,0,(int)reqStream.Length)>0)
{
builder.Append(Encoding.UTF8.GetString(buffer, 0, (int)reqStream.Length));
}