繁体   English   中英

将 wget 命令转换为 restsharp 代码

[英]translating wget command to restsharp code

我尝试执行此操作:

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

在此处采用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": ""
        }
      ]
    }
  ]
}

这是一种空虚。 所以我认为我的翻译有点不正确。 有任何想法吗?

好的,问题是缺少 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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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