ashx 错误 http 处理程序 2
我从以下 http 处理程序中收到“byte[] param = [...]”错误。其他 ashx 文件正在运行。如果您需要更多信息,请告诉我...
在此上下文中请求不可用
说明:当前 Web 请求执行期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。
异常详细信息:System.Web.HttpException:请求在此上下文中不可用
public class Handler1 : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World");
//Post back to either sandbox or live
string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr";
string strLive = "https://www.paypal.com/cgi-bin/webscr";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strSandbox);
//Set values for the request back
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
System.Web.UI.Page pa = new System.Web.UI.Page();
//HERE>HERE>HERE>HERE>
byte[] param = pa.Request.BinaryRead(HttpContext.Current.Request.ContentLength);
string strRequest = Encoding.ASCII.GetString(param);
strRequest += "&cmd=_notify-validate";
req.ContentLength = strRequest.Length;
I'm getting the an error at "byte[] param = [...]" from the following http handler. Other ashx files are working. Tell me if you need more info...
Request is not available in this context
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: Request is not available in this context
public class Handler1 : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World");
//Post back to either sandbox or live
string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr";
string strLive = "https://www.paypal.com/cgi-bin/webscr";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strSandbox);
//Set values for the request back
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
System.Web.UI.Page pa = new System.Web.UI.Page();
//HERE>HERE>HERE>HERE>
byte[] param = pa.Request.BinaryRead(HttpContext.Current.Request.ContentLength);
string strRequest = Encoding.ASCII.GetString(param);
strRequest += "&cmd=_notify-validate";
req.ContentLength = strRequest.Length;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么会调用System.Web.UI.Page的Request对象?它不会有一个,因为尚未与该请求关联。
您的代码:
它不应该读取吗?
如果您只想获取传入请求的原始字符串,那么
Why is there a call to System.Web.UI.Page's Request object? It won't have one since one hasn't been associated with the request.
Your code:
Shouldn't it read
If all you want to do is get the raw string of the incoming request.