[英]in FlUrl I try to use EnableCookies() and it throw a null reference exception
when I try to execute: 当我尝试执行时:
using (var fc = new FlurlClient().EnableCookies())
{
var resp = "http://somesite.com".GetAsync();
// var getResp = await "http://api.foo.com".GetAsync();
var resultado = await resp;
var x = resultado;
}
I get a null reference exception on EnableCookies() 我在EnableCookies()上得到一个空引用异常
stack: 堆:
en Flurl.Url.op_Implicit(Url url) en C:\Aldenteware\Flurl\code\Flurl\Url.cs:línea 315
en Flurl.Http.CookieExtensions.GetCookieContainer(FlurlClient client) en C:\Aldenteware\Flurl\code\Flurl.Http.Shared\CookieExtensions.cs:línea 145
en Flurl.Http.CookieExtensions.EnableCookies(FlurlClient client) en C:\Aldenteware\Flurl\code\Flurl.Http.Shared\CookieExtensions.cs:línea 23
en AfipProcesa.Form1.<flurlAsync>d__0.MoveNext() en c:\Users\fabian.LH\Documents\Visual Studio 2013\Projects\AfipProcesa\AfipProcesa\Form1.cs:línea 86
--- Fin del seguimiento de la pila de la ubicación anterior donde se produjo la excepción ---
en System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
en System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
en AfipProcesa.Form1.<button1_Click>d__7.MoveNext() en c:\Users\fabian.LH\Documents\Visual Studio 2013\Projects\AfipProcesa\AfipProcesa\Form1.cs:línea 119
--- Fin del seguimiento de la pila de la ubicación anterior donde se produjo la excepción ---
en System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__4(Object state)
I have to do something more or in another way? 我必须做更多或其他方式的事情?
I put it on a flurl error handler but it not catch it (as it is a null ex) 我把它放在一个flurl错误处理程序,但它没有捕获它(因为它是一个null ex)
I starting to use await/async and flurl at same time... sorry if I'm making a basic mistake. 我开始同时使用await / async和flurl ...对不起,如果我犯了一个基本错误。
I using as a example the code on http://tmenier.github.io/Flurl/client-lifetime/ 我以http://tmenier.github.io/Flurl/client-lifetime/上的代码为例
using (var fc = new FlurlClient().EnableCookies())
{
await url
.AppendPathSegment("login")
.WithClient(fc)
.PostUrlEncodedAsync(new { user = "user", pass = "pass" });
var page = await url
.AppendPathSegment("home")
.WithClient(fc)
.GetStringAsync();
// Need to inspect the cookies? FlurlClient exposes them as a dictionary.
var sessionId = fc.Cookies["session_id"].Value;
}
It looks like you've spotted a bug related to recent changes to address this issue . 您似乎发现了与最近更改相关的错误以解决此问题 。 The work-around is to seed FlurlClient with the base URL:
解决方法是使用基本URL为FlurlClient提供种子:
using (var fc = new FlurlClient(url).EnableCookies())
I'll log this issue and address it soon, it clearly doesn't work as documented. 我将记录此问题并尽快解决,但显然无法记录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.