문제

Using fiddler to observe this URL: http://opencaselist.paperlessdebate.com/bin/AllDocs?view=attachments#format=json?|t=allattachments&p=1&l=10&s=filename&d=asc

I find a nice JSON response like this enter image description here

How do I get this response into a string that I can save in a txt file using C#? Is there a way to turn an HTTP Web Response to a string? Is there something is NewtonSoft JSON that can help me? Are there particular terms that will help me google this more effectively?

Every time I try I just get an HTML version of the web-page at the link and not the JSON data I'm trying to get:

    string url = "http://opencaselist.paperlessdebate.com/bin/AllDocs?view=attachments#|t=allattachments&p=1&l=10&s=filename&d=asc";

    HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
    httpWebRequest.Method = WebRequestMethods.Http.Get;
    httpWebRequest.Accept = "text/json";
    httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
    HttpWebResponse response = (HttpWebResponse)httpWebRequest.GetResponse();
    response.Close();
도움이 되었습니까?

해결책

Note that on that screenshot, there are some differences:

  • the URL is way different: AllAttachements vs AllDocs, but that's minor, I'm pointing it out "just in case"
  • the PARAMS are way different: the screenshot specifies xpage=plain&outputSyntax=plain and your code - not
  • the HEADERS are different: your code has Accept=text\json while screenshot has Accept: text/javascript

Have you tried using the same params and headers?

EDIT: also, I've opened up the page from your code, and it actually is a page. After loading, it generates additional requests to

http://opencaselist.paperlessdebate.com/bin/get/XWiki/AllAttachmentsResults?xpage=plain&outputSyntax=plain&offset=1&limit=10&reqNo=1&sort=filename&dir=asc

which, if you download, results in JSON data. No headers at all, simple GET. I've just got the JSON data by simply pasting that URL into Chrome.. I think that you simply use wrong URL.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top