简体   繁体   中英

How to use RestSharp for a regular webpage

How would I go about using restsharp for collecting web pages which aren't explicitly api calls?

The tutorials all seem api related.

I would still be using it in a similar way, I've tried both Get and Post methods but neither seem to be returning the page that I am after? I would also say I can't tell that/if the parameters in request.Resource

http://targetwebpage.com/Results/ {date}/{track}/{race}

 var client = new RestClient("http://targetwebpage.com");
 string resource = "/Results/{date}/{track}/{race}";

 var request = new RestRequest(resource, Method.Post);
 request.AddUrlSegment("{date}", "20141001"); 
// supposed to replace matching token in request.Resource but isn't

request.AddUrlSegment("{track}", "Australia"); 
request.AddUrlSegment("{race}", "1"); 
var re = client.Execute(request);

Console.WriteLine(re.Content);

Any general pointers about my misuse of RestSharp?

RestSharp is (unsurprisingly) only intended for use with ReSTful API endpoints - I think you'd be better off using something like WebClient;

using (WebClient client = new WebClient())
{
    string htmlCode = client.DownloadString("http://www.google.com");
}

You don't specify what format the data is in which should be returned from your endpoint, so my answer is pretty much just a guess - however you should be able to process the htmlCode variable with a JSON formatter or an XML interpreter to get the results you're after. If you can supply an example of the data returned then I'd be able to help further.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM