Xml阅读器 - (403)禁止

时间:2017-02-07 16:31:29

标签: c# .net xml asp.net-mvc xmlreader

我使用Xml阅读器阅读这样的博客:

var reader = XmlReader.Create(url);

我收到一些网址错误:

  

{“远程服务器返回错误:(403)禁止。”}

如果我在浏览器中打开此网址,则效果很好。

你知道什么是错的吗?

1 个答案:

答案 0 :(得分:1)

您可以为访问网址时使用的public struct DeviceStatus { [Flags] public enum DeviceStatusMasks { None = 0x0, EmergencyButton = 0x00000001, StartButton = 0x02, Door1Interlock = 0x04, Door2Interlock = 0x08, AccessPanelInterlock = 0x10, TubeTemperature = 0x20, SystemTemperature = 0x40, DeviceTouchScreenError = 0x80, FlashValueCorrupt = 0x100, VoltageRailError3_3V = 0x200, VoltageRailError5V = 0x400, VoltageRailError24V = 0x800, HvPsuWarmUpTimerElapsed = 0x1000, // ReSharper disable InconsistentNaming kVValueOutsideRange = 0x2000, mAValueOutsideRange = 0x4000, // ReSharper restore InconsistentNaming PreheatValueError = 0x8000, FilamentCurrentError = 0x10000, KeySwitchOff = 0x00020000, StandbyButtonPressed = 0x40000, ErrorTrapState = 0x80000, PcCommunicationFailure = 0x100000 } public DeviceStatus(byte[] value) { RawValue = (DeviceStatusMasks)BitConverter.ToInt32(value.Reverse().ToArray(), 0); } #region Public Properties public bool CriticalError => EmergencyButtonPressed | TubeTemperatureHigh | SystemTemperatureHigh; public bool EmergencyButtonPressed => RawValue.HasFlag(DeviceStatusMasks.EmergencyButton); public bool StartButtonPressed => RawValue.HasFlag(DeviceStatusMasks.StartButton); public bool Door1InterlockOpen => RawValue.HasFlag(DeviceStatusMasks.Door1Interlock); public bool Door2InterlockOpen => RawValue.HasFlag(DeviceStatusMasks.Door2Interlock); public bool AccessPanelInterlockOpen => RawValue.HasFlag(DeviceStatusMasks.AccessPanelInterlock); public bool TubeTemperatureHigh => RawValue.HasFlag(DeviceStatusMasks.TubeTemperature); public bool SystemTemperatureHigh => RawValue.HasFlag(DeviceStatusMasks.SystemTemperature); public bool DeviceTouchScreenError => RawValue.HasFlag(DeviceStatusMasks.DeviceTouchScreenError); public bool FlashValueCorrupt => RawValue.HasFlag(DeviceStatusMasks.FlashValueCorrupt); public bool VoltageRailError3_3V => RawValue.HasFlag(DeviceStatusMasks.VoltageRailError3_3V); public bool VoltageRailError5V => RawValue.HasFlag(DeviceStatusMasks.VoltageRailError5V); public bool VoltageRailError24V => RawValue.HasFlag(DeviceStatusMasks.VoltageRailError24V); public bool HvPsuWarmUpTimerElapsed => RawValue.HasFlag(DeviceStatusMasks.HvPsuWarmUpTimerElapsed); // ReSharper disable InconsistentNaming public bool kVValueOutsideRange => RawValue.HasFlag(DeviceStatusMasks.kVValueOutsideRange); public bool mAValueOutsideRange => RawValue.HasFlag(DeviceStatusMasks.mAValueOutsideRange); // ReSharper restore InconsistentNaming public bool PreheatValueError => RawValue.HasFlag(DeviceStatusMasks.PreheatValueError); public bool FilamentCurrentError => RawValue.HasFlag(DeviceStatusMasks.FilamentCurrentError); public bool KeySwitchOff => RawValue.HasFlag(DeviceStatusMasks.KeySwitchOff); public bool StandbyButtonPressed => RawValue.HasFlag(DeviceStatusMasks.StandbyButtonPressed); public bool ErrorTrapState => RawValue.HasFlag(DeviceStatusMasks.ErrorTrapState); public bool PcCommunicationFailure => RawValue.HasFlag(DeviceStatusMasks.PcCommunicationFailure); public bool HasNoStatus { get { return !(StandbyButtonPressed | Door1InterlockOpen | Door2InterlockOpen | AccessPanelInterlockOpen | KeySwitchOff | CriticalError); } } #endregion public DeviceStatusMasks RawValue { get; } 提供凭据;这可能是你在你的环境中需要做的事情。有关详细信息,请参阅https://msdn.microsoft.com/en-us/library/47as68k4(v=vs.71).aspx

您还可以使用带有凭据的XmlReader对象将响应作为HttpClient并使用Stream代替。