从URL读取xml

时间:2012-10-12 17:58:24

标签: c# asp.net

我正在尝试从url读取xml(以及它不是url它的restful服务),下面是我的代码。我不知道问题是什么,但我无法从url读取xml。我收到错误,我没有得到任何数据..

    string soap = "";
if (fPortalGuid != string.Empty)
{
    HttpWebRequest request = WebRequest.Create("http://cramapp-dt-02s.cable.comcast.com:8158/restfulqueryservice/queryservice/getrequestdetails?api_key=......&request_id=33ebc6e9-9def-4f39-adf9-bba2edef3b54") as HttpWebRequest;
    //request.Credentials = new NetworkCredential("rolland", "409cleaner");
    //request.ContentType = "application / json; charset = utf - 8";
    request.Method = "POST";

    using (Stream stm = request.GetRequestStream())
    {
        using (StreamWriter stmw = new StreamWriter(stm))
        {
            stmw.Write(soap);
        }
    }
    // Get response  
    using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
    {
        // Get the response stream  
        StreamReader reader = new StreamReader(response.GetResponseStream());
        // Console application output  
        Console.WriteLine(reader.ReadToEnd());
    }
}

,xml看起来像这个xml file image

1 个答案:

答案 0 :(得分:0)

此行可能会出错

HttpWebRequest request = WebRequest.Create("http://cramapp-dt-02s.cable.comcast.com:8158/restfulqueryservice/queryservice/getrequestdetails?api_key=......&request_id=33ebc6e9-9def-4f39-adf9-bba2edef3b54") as HttpWebRequest;

因为创建函数中的url无法访问(太长,所以有...用于显示呼叫),请尝试找到并粘贴完整链接或此链接:

http://www.w3schools.com/xml/note.xml