开发者

Phase REST XML into variable

I want to get a response from the REST XML web service, and phase it into variables so I can use them in my program.

1) How come this code does not work? I get an empty string...

// Get response 
string ws_response="";
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)  
{  
    // Get the response stream  
    StreamReader reader = new StreamReader(response.GetResponseStream());


    // web service response string
    ws_response = reader.ReadToEnd;  // <---???? I get an empty string

    // do phasing here (ie XML element into variable) etc..
开发者_运维百科    //
}  


Have you check the response.StatusCode? It may not be ok (200) - that may tell you the issue. Another idea is to try the web request in browser - do you get output there? If not then you need to contact web service provider to understand what is missing - may be it is expecting some headers in request etc. If it works in browser then use tool such as Fiddler to inspect the request going in. Compare that request with the one that you are making from your code. Another possible issue (when it working in browser) can be that browser is doing authentication transparently and that may not be happening in your code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜