简体   繁体   中英

translating wget command to restsharp code

I try to execute this:

wget --post-data 'The quick brown fox jumped over the lazy dog.' 'localhost:9000/?properties={"annotators":"tokenize,ssplit,pos","outputFormat":"json"}' -O -

Taken form here into C# RestSharp code. AFIK this is a post request? So I went for this code:

var client = new RestClient(@"http://localhost:9000/?properties={""annotators"":""tokenize,ssplit,pos"", ""outputFormat"":""json""}")
{
    Timeout = 5000 
};

var request = new RestRequest(Method.POST);
request.AddBody(@"The quick brown fox jumped over the lazy dog.");
var response = client.Execute(request);

This returns:

{
  "sentences": [
    {
      "index": 0,
      "tokens": [
        {
          "index": 1,
          "word": "<String />",
          "originalText": "<String />",
          "characterOffsetBegin": 0,
          "characterOffsetEnd": 10,
          "pos": "ADD",
          "before": "",
          "after": ""
        }
      ]
    }
  ]
}

which is kind of empty. So I assume my translation is somewhat incorrect. Any ideas?

Ok the issue was the missing DataFormat.Json (see working code below). Maybe this is useful for someone else

var client = new RestClient(@"http://localhost:9000/?properties={""annotators"":""tokenize,ssplit,pos"", ""outputFormat"":""json""}")
{
    Timeout = 5000 
};

var request = new RestRequest(Method.POST)
{
    RequestFormat = DataFormat.Json
};
request.AddBody(@"The quick brown fox jumped over the lazy dog.");
var response = client.Execute(request);

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