Flurl.Http PostMultipartAsync导致一些错误

时间:2019-03-25 04:23:54

标签: flurl

我正在将一些数据发布到服务器。这段代码几个月前运行良好。但是现在它抛出了“ Flurl.Http.FlurlHttpException”。

Flurl.Http 2.3.2

string res = "";
try
{
   var obj = new { api_key = "key", api_secret = "secret", start = 1 };
   res = await "https://api-cn.faceplusplus.com/facepp/v3/faceset/getfacesets"
         .PostMultipartAsync(mp => mp
         .AddStringParts(obj)
         ).ReceiveString();

}
catch (FlurlHttpException ex)
{
    Debug.WriteLine(ex.Message);
}

唯一的区别是Win10版本,从1803年到1809年。 我更改为使用“ PostUrlEncodedAsync”,服务器返回成功。 但是此方法无法添加文件。

res = await apiUrl
    .PostUrlEncodedAsync(obj)
    .ReceiveString();

这是FlurlHttpException:

enter image description here

{Flurl.Http.FlurlHttpException: Call failed with status code 400 (): POST https://api-cn.faceplusplus.com/facepp/v3/faceset/getfacesets
   at Flurl.Http.FlurlRequest.<HandleExceptionAsync>d__23.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at Flurl.Http.FlurlRequest.<SendAsync>d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Flurl.Http.FlurlRequest.<SendAsync>d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Flurl.Http.HttpResponseMessageExtensions.<ReceiveString>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at FacePlusPlusUWP.FaceServiceClient.<SendRequestAsync>d__26.MoveNext()}

1 个答案:

答案 0 :(得分:0)

new Index() { ... Analyzers = new[] { new CustomAnalyzer() { Name = "keyword_lowercase", Tokenizer = TokenizerName.Keyword, TokenFilters = new[] { TokenFilterName.Lowercase } } } } 所示,您从服务器收到400(错误请求)响应。我不熟悉您使用的API,但是我要检查的第一件事是服务器是否向您发送了有用的响应正文。您可以在{ [Key] public string Id { get; set; } [IsSearchable] [Analyzer("keyword_lowercase")] public string AccountId { get; set; } } 块中执行以下操作:

{
    "fields": [{
        "name": "Id",
        "type": "Edm.String",
        "key": true
    },
    {
        "name": "AccountId",
        "type": "Edm.String",
        "searchable": true,
        "retrievable": true,
        "analyzer": "keyword_lowercase"
     }],
    "analyzers":[
        {
           "name":"keyword_lowercase",
           "@odata.type":"#Microsoft.Azure.Search.CustomAnalyzer",
           "tokenizer":"keyword_v2",
           "tokenFilters":["lowercase"]
        }
     ]
}