我正在为SocketIO构建一些测试工具,该工具将允许用户连接到任何SocketIO后端。
当我尝试连接到其他域时,按预期出现CORS错误。
由于在这种情况下我不控制服务器端,因此添加标头的标准解决方案是无关紧要的。
无论是通过SocketIO本身还是仅使用普通的JS,有什么方法可以克服它吗?
这是我安装React组件时用来连接的基本代码:
<control:ListViewNestedScroll
x:Name="ClassLevelListView"
HasUnevenRows="True"
RowHeight="30"
SeparatorVisibility="None"
IsPullToRefreshEnabled="True"
IsRefreshing="{Binding IsRunning, Mode=TwoWay}"
RefreshCommand="{Binding LoadClassLevelsCommand}"
ItemsSource="{Binding ClassLevels}">
<ListView.ItemTemplate>
<DataTemplate>
<control:CustomViewCell SelectedBackgroundColor="{StaticResource GreyColor}">
<StackLayout Margin="0,0,0,10">
<control:CustomButton
Text="{Binding KeyName, Converter={StaticResource I18N}}"
CornerRadius="20"
BorderColor="Black"
BorderWidth="2"
TextColor="Black"
BackgroundColor="White"
CommandParameter="{Binding .}"
Clicked="Button_OnClicked" />
</StackLayout>
</control:CustomViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</control:ListViewNestedScroll>
private void Button_OnClicked(object sender, EventArgs e)
{
var classLevelButton = (Button)sender;
var classLevel = classLevelButton.CommandParameter as ClassLevelModel;
if (classLevelButton.BackgroundColor == Color.White)
{
classLevelButton.BackgroundColor = (Color)Application.Current.Resources["GreyColor"];
((RegisterTeacherClassLevelViewModel)BindingContext).AddTeacherClassLevel(classLevel);
}
else
{
classLevelButton.BackgroundColor = Color.White;
((RegisterTeacherClassLevelViewModel)BindingContext).RemoveTeacherClassLevel(classLevel);
}
}