HttpWebRequiest.AllowAutoRedirect不PCL
问题描述:
发现
我是新来Xamarin,所以我希望这不是为客户使用一个愚蠢的问题:)HttpWebRequiest.AllowAutoRedirect不PCL
我开发一个PCL将作为SDK(NuGet包)函数为他们的Http APIs。 在iOS和Android上都有很多逻辑需要完成,所以我认为PCL是一条可行的路线。 我打包的API是HttpWebRequest,基本上我公开了完全相同的API并在请求发送之前处理这些请求。
我需要做的一件事是确保所有重定向都经过我,以便控制cookie。
我发现proper way做到这一点是设置: HttpWebRequest.AllowAutoRedirect = false
然而,当我尝试这一点,我得到一个错误: “HttpWebRequest的”不包含一个定义为“AllowAutoRedirect” .. 。
这是一个示例代码:
using System;
using System.IO;
using System.Net;
using System.Threading.Tasks;
namespace PCLTest.Net
{
public class MyHttpWebRequest
{
HttpWebRequest request;
public bool AllowAutoRedirect
{
get
{
return request.AllowAutoRedirect;
}
set
{
request.AllowAutoRedirect = value;
}
}
}
}
我缺少什么?
答
OK删除,所以我也没弄明白为什么这个API是隐藏的,如何使框架揭露它,但我最终解决这个问题的方式是这样的:
using System;
using System.IO;
using System.Net;
using System.Threading.Tasks;
namespace PCLTest.Net
{
public class MyHttpWebRequest
{
HttpWebRequest request;
public bool AllowAutoRedirect
{
get
{
Type t = request.GetType();
PropertyInfo pi = t.GetRuntimeProperty("AllowAutoRedirect");
return (bool)pi.GetValue(request);
}
set
{
request.AllowAutoRedirect = value;
}
}
}
}
答
从PLC目标的Windows Phone(ProjectName->选项 - >常规)
不是,那并没有工作。我尝试了几个没有Windows手机的配置文件,它不起作用。是否有包含在哪个配置文件中的API的文档? – Yoshkebab