3

RestSharpのAddUrlSegmentを使用してURLのトークンをサブ化しようとしています

例:「www.test.com/{someToken}/Testing」

私はこのコードを使用しています:

string theToken = "someStringToken";
restRequest.AddUrlSegment("someToken",theToken);

リクエストを実行しようとすると、NullReferenceExceptionがスローされます。

私が間違っていることについての考え。

ありがとう。

4

2 に答える 2

2

Alright I figured this out. The version of RestSharp I have (NUGET), apparently does not support the method above. Also the Resource property is the one that should be getting the url that is going to be replaced so the final code is something like this.

string _baseUrl = "www.test.com";

RestClient client = new RestClient(_baseUrl);
RestRequest restRequest = new Request();
restRequest.Resource = "/{someToken}/Testing";
restRequest.AddParameter("someToken", theToken , ParameterType.UrlSegment);

This piece of code works with the version I got from NUGET

于 2012-06-28T04:20:42.287 に答える
1

I got the same problem.

Here is some alternative solution code with passing resource in constructor and simplified method call, using RestSharp v.104.4.0:

string _baseUrl = "www.test.com";

var client = new RestClient(_baseUrl);
var req = new RestRequest("/{someToken}/Testing", Method.GET);
req.RequestFormat = DataFormat.Json;
req.AddUrlSegment("someToken", theToken);
于 2014-12-23T10:43:27.160 に答える