6
<?xml version="1.0" encoding="utf-8"?>
<rsp stat="ok">
        <image_hash>cxmHM</image_hash>
        <delete_hash>NNy6VNpiAA</delete_hash>
        <original_image>http://imgur.com/cxmHM.png</original_image>
        <large_thumbnail>http://imgur.com/cxmHMl.png</large_thumbnail>
        <small_thumbnail>http://imgur.com/cxmHMl.png</small_thumbnail>
        <imgur_page>http://imgur.com/cxmHM</imgur_page>
        <delete_page>http://imgur.com/delete/NNy6VNpiAA</delete_page>
</rsp>

这是我会收到的典型回复。我尝试了以下方法,但我收到一个错误,告诉我不能将非空白字符添加到内容中。

XDocument response = new XDocument(w.UploadValues("http://imgur.com/api/upload.xml", values));    
4

2 回答 2

11
byte[] responseData = w.UploadValues("http://imgur.com/api/upload.xml", values);
string responseText = Encoding.ASCII.GetString(responseData);  //  ASCII assumed
XDocument respnseXml = XDocument.Parse(responseText); 

但是那个错误也可能来自values.

于 2010-08-10T15:39:34.507 回答
5

我体验过最好将字节加载到 MemoryStream 中并将其提供给 XDocument。这样您就不必修复任何空白问题。

byte[] responseData = w.UploadValues("http://imgur.com/api/upload.xml", values);
using(var ms = new MemoryStream(responseData)) 
{
var responseXml = XDocument.Load(ms);
}
于 2018-05-18T13:21:44.000 回答