【问题标题】:translating wget command to restsharp code将 wget 命令转换为 restsharp 代码
【发布时间】:2021-07-23 08:45:20
【问题描述】:

我尝试执行此操作:

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

here 转换为C# RestSharp 代码。 AFIK 这是一个帖子请求?所以我选择了这段代码:

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);

这会返回:

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

这有点空。所以我认为我的翻译有些不正确。有什么想法吗?

【问题讨论】:

  • 您期望得到什么?你从 wget 命令得到什么?

标签: c# stanford-nlp restsharp


【解决方案1】:

好的,问题是缺少 DataFormat.Json(请参阅下面的工作代码)。也许这对其他人有用

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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-22
    • 2017-11-23
    • 2022-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-27
    相关资源
    最近更新 更多