首页 \ 问答 \ C#发布XML到URL不起作用(C# Post XML to URL not working)

C#发布XML到URL不起作用(C# Post XML to URL not working)

首先,我是一个WEB NOOB。 这可能解释了这个问题。 无论如何,当我使用网页测试应用程序将xml发布到网址时,一切正常。 这里是从网页(我认为)pertinant代码:

<form action="/gateway/xml" method="post" id="xml-test-form">
  <textarea name="data">

  {some xml is in here}

  </textarea>
  <input type="submit" value="Submit Test" />
</form>

当我尝试使用缓存编码(ASCII或UTF8)的内容类型(“text / xml”或“application / x-www-form-urlencoded”)的C#(WebRequest或HttpWebRequest)提交完全相同的XML时,这意味着XML不能在另一端读取。 这是错误:

<?xml version="1.0"?>
<SubmitOrdersResponse>
  <status code="0">FAILURE</status>
  <errors>
    <error code="1001">Invalid XML Version</error>
  </errors>
</SubmitOrdersResponse>
<br /><b>Warning</b>:  DOMDocument::loadXML() [<a href='domdocument.loadxml'>domdocument.loadxml</a>]: Empty string supplied as input in <b>/var/www/vhosts/reports.gogetagrip.com/httpdocs/application/models/Gateway.php</b> on line <b>90</b><br />

我可以通过删除名为的XML元素使用Web测试人员重现此错误。 我认为这是检查的第一个元素,因此是“INVALID XML VERSION”错误。 我认为发生的事情是我的提交文件以不正确的格式发送,并且该内容不能被读取。 具体而言,我认为我必须模拟发布数据,其中数据来自“数据”表单字段(参见上文)。 我不知道如何使用WebRequest类来设置它,所以我无法测试它。 这是我的代码:

static private void Post(string sURL, string sXml) {
  try {
    //Our postvars
    byte[] buffer = Encoding.UTF8.GetBytes(sXml);  // Tried ASCII...same result
    HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(sURL);  // Tried WebRequest ... same result
    WebReq.Method = "POST";
    WebReq.ContentType = "application/x-www-form-urlencoded";  // tried "text/xml"... same result
    WebReq.ContentLength = buffer.Length;
    Stream ReqStream = WebReq.GetRequestStream();
    ReqStream.Write(buffer, 0, buffer.Length);
    ReqStream.Close();
    WebResponse WebRes = WebReq.GetResponse();
    //Console.WriteLine(WebResp.StatusCode);
    //Console.WriteLine(WebResp.Server);
    Stream ResStream = WebRes.GetResponseStream();
    StreamReader ResReader = new StreamReader(ResStream);
    string sResponse = ResReader.ReadToEnd();
  } catch (Exception ex) {

  } finally {

  }
}

有任何想法吗?????


First of all, I am a WEB NOOB. Which probably explains this question. Anyway, when I use the web page test app to post xml to a url, everything works fine. Here is the pertinant code from the web page (i think):

<form action="/gateway/xml" method="post" id="xml-test-form">
  <textarea name="data">

  {some xml is in here}

  </textarea>
  <input type="submit" value="Submit Test" />
</form>

When I try to submit the exact same XML using C# (WebRequest or HttpWebRequest) with content type of ("text/xml" or "application/x-www-form-urlencoded") with a buffer encoded (ASCII or UTF8) I get an error that implies the XML cant be read at all on the other end. Here is the error:

<?xml version="1.0"?>
<SubmitOrdersResponse>
  <status code="0">FAILURE</status>
  <errors>
    <error code="1001">Invalid XML Version</error>
  </errors>
</SubmitOrdersResponse>
<br /><b>Warning</b>:  DOMDocument::loadXML() [<a href='domdocument.loadxml'>domdocument.loadxml</a>]: Empty string supplied as input in <b>/var/www/vhosts/reports.gogetagrip.com/httpdocs/application/models/Gateway.php</b> on line <b>90</b><br />

I can reproduce this error using the web tester by removing a XML element named . I think this is the first element that is checked for, and hence the "INVALID XML VERSION" error. I think what is happening is my submittal is comming accross slighlty in the wrong format and that element can't be read. I think specifically I have to simulate a posting data where my data is comming from the "data" form field (see above). I don't know how to set that using the WebRequest class, so I can't test it. Here is my code:

static private void Post(string sURL, string sXml) {
  try {
    //Our postvars
    byte[] buffer = Encoding.UTF8.GetBytes(sXml);  // Tried ASCII...same result
    HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(sURL);  // Tried WebRequest ... same result
    WebReq.Method = "POST";
    WebReq.ContentType = "application/x-www-form-urlencoded";  // tried "text/xml"... same result
    WebReq.ContentLength = buffer.Length;
    Stream ReqStream = WebReq.GetRequestStream();
    ReqStream.Write(buffer, 0, buffer.Length);
    ReqStream.Close();
    WebResponse WebRes = WebReq.GetResponse();
    //Console.WriteLine(WebResp.StatusCode);
    //Console.WriteLine(WebResp.Server);
    Stream ResStream = WebRes.GetResponseStream();
    StreamReader ResReader = new StreamReader(ResStream);
    string sResponse = ResReader.ReadToEnd();
  } catch (Exception ex) {

  } finally {

  }
}

Any Ideas?????


原文:https://stackoverflow.com/questions/1368419
更新时间:2023-06-25 08:06

最满意答案

这是关于如何向CellTable添加数据的CellTable 。 例如,你可以

myDataProvider.setList(rowData);

要么

myTable.setRowData(rowData);

但上述两种方法都不允许对数据进行排序。 那是因为,您已经使用空列表定义了ListHandler 。 并且它不会注意到列表已更改,因此不会执行排序。

请参阅ListDataProvider文档

getList()返回的列表的修改(插入,移除,设置等)将反映在模型中。 但是,列表中包含的项目的突变不会反映在模型中。 您必须调用List.set(int,Object)来更新列表中的项目并将更改推送到显示,或调用refresh()将所有行推送到显示。 List.set(int,Object)执行得更好,因为它允许数据提供程序仅推送已更改的那些行,并且通常允许显示仅重新呈现行的子集。

所以,你应该先getList()并改变它:

myDataProvider.getList().clear();
myDataProvider.getList().addAll(rowData);

It is all about how do you add data to the CellTable. For example, you can

myDataProvider.setList(rowData);

or

myTable.setRowData(rowData);

but both above methods will not allow the data to be sorted. That is because, you already have ListHandler defined with an empty list. And it will not notice that the list have changed, so no sorting will be performed.

See ListDataProvider documentation:

Modifications (inserts, removes, sets, etc.) to the list returned by getList() will be reflected in the model. However, mutations to the items contained within the list will NOT be reflected in the model. You must call List.set(int, Object) to update the item within the list and push the change to the display, or call refresh() to push all rows to the displays. List.set(int, Object) performs better because it allows the data provider to push only those rows which have changed, and usually allows the display to re-render only a subset of the rows.

So, you should first getList() and change it like this:

myDataProvider.getList().clear();
myDataProvider.getList().addAll(rowData);

相关问答

更多

相关文章

更多

最新问答

更多
  • 您如何使用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)