簡體   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