首页 \ 问答 \ 读取URLLoader的服务器错误消息(Reading server error messages for a URLLoader)

读取URLLoader的服务器错误消息(Reading server error messages for a URLLoader)

我有一个带有以下代码的URL加载器:

public function getUploadURL():void {   
    var request:URLRequest = new URLRequest();

    var url:String = getPath();
    // Adds time to prevent caching
    url += "&time=" + new Date().getTime(); 

    request.url = url;
    request.method = URLRequestMethod.GET;

    _loader = new URLLoader();
    _loader.dataFormat = URLLoaderDataFormat.TEXT;
    _loader.addEventListener(Event.COMPLETE, getBaseURL);
    _loader.addEventListener(IOErrorEvent.IO_ERROR, onGetUploadURLError);
    _loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, getHttpStatus);

    _loader.load(request);
}

我的问题是这个请求可能是错误的,因此服务器会给我一个400 Bad Request,并提供一条消息来解释错误。 如果Event.COMPLETE,我可以在Event的“data”字段中看到服务器返回的一些消息(响应),但是如果调用onGetUploadURLError或getHttpStatus,它只是说错误代码是400但是没有显示我与之相关的信息。

“data”字段在getHttpStatus中未定义,而在onGetUploadURLError中为“”。 相反,在getBaseURL中,我得到:{“ResponseMetadata”:{...}}我检查过,我在浏览器中得到了类似的错误请求,但我看不到它。

知道我怎么可以取消消息?

非常感谢,鲁迪


I have an URL loader with the following code:

public function getUploadURL():void {   
    var request:URLRequest = new URLRequest();

    var url:String = getPath();
    // Adds time to prevent caching
    url += "&time=" + new Date().getTime(); 

    request.url = url;
    request.method = URLRequestMethod.GET;

    _loader = new URLLoader();
    _loader.dataFormat = URLLoaderDataFormat.TEXT;
    _loader.addEventListener(Event.COMPLETE, getBaseURL);
    _loader.addEventListener(IOErrorEvent.IO_ERROR, onGetUploadURLError);
    _loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, getHttpStatus);

    _loader.load(request);
}

My problem is that this request might be wrong, and so the server will give me a back a 400 Bad Request, with a message to explain the error. If the Event.COMPLETE, I can see some message (a response) back from the server in the "data" field of the Event, but if onGetUploadURLError or getHttpStatus is called, it just says that the error code is 400 but does not show me the message associated with it.

The "data" field is undefined in getHttpStatus and it is "" in onGetUploadURLError. On the contrary, in getBaseURL, I get: {"ResponseMetadata":{...}} I checked and I do get a similar response in my browser for a wrong request, but I cannot see it.

Any idea how I can please get the message?

Thank you very much, Rudy


原文:https://stackoverflow.com/questions/3009870
更新时间:2022-07-02 14:07

最满意答案

您可以将对输入控件的引用作为JS函数的参数传递,即:

<INPUT id="EquipmentCost" type="text" name="EquipmentCost" runat="server" size="10" onchange="TotalCost(this);" class="bk">

function TotalCost(txtEquipCost) {
var a = txtEquipCost.value;
}

然后id是什么并不重要。

编辑:
如果您有更多控件,请在页面上创建JS变量,例如:

var txtEquipCost = document.getElementById('<%= YourControl.ClientID %>');
var txtOtherCost = document.getElementById('<%= YourOtherControl.ClientID %>');

那么onChange函数调用可能是TotalCost(txtEquipCost,txtOtherCost)

EDIT2:
请参阅有关ClientId和UniqueId的问题,这可能很有用: C#asp.net为什么ClientID和UniqueID之间存在差异?


You could pass in a reference to the input control as a parameter to the JS function, ie:

<INPUT id="EquipmentCost" type="text" name="EquipmentCost" runat="server" size="10" onchange="TotalCost(this);" class="bk">

function TotalCost(txtEquipCost) {
var a = txtEquipCost.value;
}

Then it doesn't matter what the id is.

EDIT:
If you have more controls, create JS variables on the page, eg:

var txtEquipCost = document.getElementById('<%= YourControl.ClientID %>');
var txtOtherCost = document.getElementById('<%= YourOtherControl.ClientID %>');

Then the onChange function call could be TotalCost(txtEquipCost, txtOtherCost)

EDIT2:
See this question about ClientId and UniqueId which may be useful: C# asp.net Why is there a difference between ClientID and UniqueID?

相关问答

更多
  • 使用ASP.Net 1.1,首先必须在标题标记上设置runat属性: WebForm1 然后从后面的代码: C# // We need this name space to use HtmlGenericControl using System.Web.UI.HtmlControls; namespace TestWebApp { public class WebForm1 : System.Web. ...
  • 我不知道为什么你在标记中拼出一个字符串而不是代码,但无论如何。 将此字符串分配给验证器,如下所示:
  • 不,不是的。 仅限ASP.NET 2.0及更高版本。 No it does not. ASP.NET 2.0 and above only.
  • 只要确保您在同一个应用程序池中不运行不同的Web应用程序(如果它们需要不同版本的.NET框架)。 创建单独的应用程序池(每个版本的框架至少有一个)。 也许还可以看看Brad Abrams撰写的关于突破.NET Framework 1.1和2.0之间的变化的博客文章 。 这里有一个简短的报价: ...我们非常努力地确保您的V1.1应用程序只能在2.0版本上运行,但无论如何,这个文档在您迁移到2.0时可能值得一次快速扫描 Just make sure that you are not running diffe ...
  • 不幸的是,在ASP.Net 2.0中添加了Wizard控件。 您可以使用面板和按钮创建类似的外观 Unfortunately the Wizard control was added in ASP.Net 2.0. You can create a comparable look-alike with Panels and buttons
  • 它现在可以在MyGet上的每晚版本中使用( https://www.myget.org/gallery/aspnetwebstacknightly ),并且应该在Asp.Net Identity的下一个版本中。 It is available right now in the nightly builds available on MyGet (https://www.myget.org/gallery/aspnetwebstacknightly) and should be in the next rel ...
  • 我在这里找到了Asp.net 1.1的HtmlAgilityPack http://www.codefluent.com/smourier/download/htmlagilitypack.zip这里有几个.cs文件。 要在Asp.net 1.1中使用它,只需使用assembly指令在aspx页面中导入 http://msdn.microsoft.com/en-us/library/d864zc1k%28v=vs.71%29.aspx 这样的东西...... <%@ Assembly Src="File1. ...
  • 我越来越认为不是。 目前仍然坚持1.1的大型僵化组织(可能因为它们只是刚刚升级到它)也是那种极不可能关注开源解决方案的组织。 如果我现在开始一个新的ASP.Net项目,我会坚持.Net 3.5,可能还有新的MVC预览。 Increasingly I think not. The kind of large rigid organisation currently still clinging to 1.1 (probably because they're only just upgraded to it) ...
  • 您创建的下拉列表与模型中的任何属性都没有关系。 第一个绑定到名为Student的属性,该属性不存在。 第二个绑定到名为Subject的属性,该属性也不存在。 第3个绑定到属性Session ,它是复杂对象的集合( IEnumerable ),但 function TotalCost(txtEquipCost) { var a = txtEquipCost.value; } 然后id是什么并不重要。 编辑: 如果您有更多控件,请在页面上创建JS变量, ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)