У меня странная проблема с доступом к следующему URL :
Вот код:
void WebRequestButton_Click( object sender, RoutedEventArgs e )
{
string url = "http://xn--fanbys-exa.org/episodes.m4a.rss";
if ( Uri.IsWellFormedUriString( url, UriKind.Absolute ) )
{
HttpWebRequest webRequest = ( HttpWebRequest )HttpWebRequest.Create( url );
if ( webRequest != null )
{
webRequest.BeginGetResponse( new AsyncCallback( ReadWebRequestCallback ), webRequest );
}
}
}
private void ReadWebRequestCallback( IAsyncResult callbackResult )
{
HttpWebRequest request = ( HttpWebRequest )callbackResult.AsyncState;
HttpWebResponse response = null;
try
{
response = ( HttpWebResponse )request.EndGetResponse( callbackResult );
}
catch ( Exception e )
{
System.Diagnostics.Debug.WriteLine( e );
}
if ( response != null )
{
using ( StreamReader httpwebStreamReader = new StreamReader( response.GetResponseStream( ) ) )
{
string results = httpwebStreamReader.ReadToEnd( );
System.Diagnostics.Debug.WriteLine( results );
}
response.Close( );
}
}
Чтение ответа с помощью request.EndGetResponse() вызывает это исключение:
A first chance exception of type 'System.ArgumentException' occurred in System.Windows.dll
System.ArgumentException ---> System.ArgumentException: The parameter is incorrect.
at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
at MS.Internal.XcpImports.WebRequest_Send(InternalWebRequest request)
at MS.Internal.InternalWebRequest.Send()
at System.Net.Browser.ClientHttpWebRequest.PrepareAndSendRequest(String method, Uri requestUri, Stream requestBodyStream, WebHeaderCollection headerCollection, CookieContainer cookieContainer)
at System.Net.Browser.ClientHttpWebRequest.BeginGetResponseImplementation()
at System.Net.Browser.ClientHttpWebRequest.InternalBeginGetResponse(AsyncCallback callback, Object state)
at System.Net.Browser.ClientHttpWebRequest.BeginGetResponse(Async'UI Task' (Managed): Loaded 'System.Runtime.Serialization.dll'
Как насколько я могу судить, URL-адрес
правильно сформирован.
Все браузеры, которые я пробовал, справляются с этим.
Тестирование с помощью Fiddler показывает, что HTTP-запросы не отправляются с эмулятора Windows Phone.
При использовании нескольких разных URL-адресов (с активным экземпляром Fiddler):
string url = "http://xn--fanbys-exa.org/episodes.m4a.rss";
// not ok --> System.ArgumentException: The parameter is incorrect.
string url = "http://xn--fanbys-exa.org";
// not ok --> System.ArgumentException: The parameter is incorrect.
string url = Uri.EscapeUriString( "http://xn--fanbys-exa.org/episodes.m4a.rss" );
// not ok --> System.ArgumentException: The parameter is incorrect.
string url = "http://stackoverflow.com";
// ok, HTTP request is sent and response is received
string url = "http://stack--overflow.com";
// ok, HTTP request is sent and response is received
string url = "http://xn--stackoverflow.com";
// ok, HTTP request is sent and response 502 is received
// --> System.Net.WebException: The remote server returned an error: NotFound.
Проблема может быть воспроизведена в эмуляторе и на устройстве.
Я предполагаю, что это может быть связано с DNS.
У меня нет контроля над указанным веб-сайтом и его DNS-записью.
Есть идеи?