7

I have a strange issue accessing the following url:

http://xn--fanbys-exa.org/episodes.m4a.rss


Here is the code:

    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( );
        }
    }


Reading the response with request.EndGetResponse() throws this exception:

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'


As far as I can tell the url

http://xn--fanbys-exa.org/episodes.m4a.rss

is wellformed.
All browsers that I tried can handle it.

Testing with Fiddler shows that no HTTP request is being sent from the Windows Phone emulator.

If have tried several different URLs (with an active Fiddler instance):

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.

The issue can be reproduced with the emulator and on the device.
My guess is that this might be DNS related.
I have no control over the referenced web site and its DNS entry.

Any ideas ?

Volker Voecking
  • 5,203
  • 2
  • 38
  • 35
  • Tried it out and it's indeed something strange. Code works like a charm using any url provided except for those in the fanbóys.org/ domain. – Tim Dams Jun 04 '12 at 13:04

1 Answers1

0

Yup, I can verify the problem too, and also see no traffic in fiddler. Weirdest error ever!

  string url = "http://a--b-c.org"; - Fine
  string url = "http://xn--fanbys-exa.org"; - Error
  string url = "http://xn--2fanbys-exa.org"; - Error
  string url = "http://xn--fanbys2-exa.org"; - Error
  string url = "http://xn--fan2bys-exa.org"; - Error
  string url = "http://xn-fanbys-exa.org"; - Fine
  string url = "http://xn--b-exa.org"; - Fine
  string url = "http://xn--f.org"; - Fine
  string url = "http://a--fanbys-exa.org"; - Fine
  string url = "http://xn--fanbys-c.org"; - Fine
  string url = "http://xn--fanbys-exa2.org"; - Fine
  string url = "http://2xn--fanbys-exa.org"; - Fine
  string url = "http://xn--f-exa.org"; - Fine
  string url = "http://xn--fs-exa.org"; - Error
  string url = "http://x--fs-exa.org"; - Fine
  string url = "http://xn--fs.org"; - Fine
  string url = "http://xn--fs-.org"; - Fine
  string url = "http://xn--fs-e.org"; - Fine
  string url = "http://xn--fs-ea.org"; - Fine
  string url = "http://xn--fs-ex.org"; - Fine
  string url = "http://xn--fs-exx.org"; - Error
  string url = "http://xn--fs-eee.org"; - Error
  string url = "http://aa--aa-aaa.org"; - Fine
  string url = "http://aa--aa-eee.org"; - Fine
  string url = "http://xa--aa-eee.org"; - Fine
  string url = "http://xa--fs-eee.org"; - Fine
  string url = "http://zn--fs-eee.org"; - Fine
  string url = "http://xn--fa-eee.org"; - Error
  string url = "http://xn--faa-eee.org"; - Error
  string url = "http://xn--faaaaaaaaaaaaa-eee.org"; - Error
  string url = "http://xn--faaaaaaaaaaaaaeee.org"; - Fine

Interestingly, the exception has already occurred before 'EndGetResponse' - if you look in the private field '_exception' just before 'EndGetResponse' is called.

Unsurprisingly, WebClient also shows a similar issue:

        const string url = "http://xn--fanbys-exa.org/episodes.m4a.rss";

        var wc = new WebClient();
        wc.DownloadStringCompleted += (o, args) =>
                                          {
                                              Debug.WriteLine(args.Result);
                                          };

        wc.DownloadStringAsync(new Uri(url, UriKind.Absolute));

Yields:

  System.Net.WebException was unhandled
    Message=An exception occurred during a WebClient request. 
    StackTrace:
         at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()
         at System.Net.DownloadStringCompletedEventArgs.get_Result()
         at OddballHttp.MainPage.<MainPage_Loaded>b__0(Object o, DownloadStringCompletedEventArgs args)
         at System.Net.WebClient.OnDownloadStringCompleted(DownloadStringCompletedEventArgs e)
         at System.Net.WebClient.DownloadStringOperationCompleted(Object arg)
         at System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)
         at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
         at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
         at System.Delegate.DynamicInvokeOne(Object[] args)
         at System.MulticastDelegate.DynamicInvokeImpl(Object[] args)
         at System.Delegate.DynamicInvoke(Object[] args)
         at System.Windows.Threading.DispatcherOperation.Invoke()
         at System.Windows.Threading.Dispatcher.Dispatch(DispatcherPriority priority)
         at System.Windows.Threading.Dispatcher.OnInvoke(Object context)
         at System.Windows.Hosting.CallbackCookie.Invoke(Object[] args)
         at System.Windows.Hosting.DelegateWrapper.InternalInvoke(Object[] args)
         at System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(IntPtr pHandle, Int32 nParamCount, ScriptParam[] pParams, ScriptParam& pResult)
    InnerException: System.ArgumentException
         Message=""
         StackTrace:
              at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
              at System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
              at System.Net.WebClient.GetWebResponse(WebRequest request, IAsyncResult result)
              at System.Net.WebClient.DownloadBitsResponseCallback(IAsyncResult result)
              at System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClassa.<InvokeGetResponseCallback>b__8(Object state2)
              at System.Threading.ThreadPool.WorkItem.WaitCallback_Context(Object state)
              at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
              at System.Threading.ThreadPool.WorkItem.doWork(Object o)
              at System.Threading.Timer.ring()
         InnerException: System.ArgumentException
              Message=The parameter is incorrect. 
              StackTrace:
                   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(AsyncCallback callback, Object state)
                   at System.Net.WebClient.DownloadBits(WebRequest request, Stream writeStream, CompletionDelegate completionDelegate, AsyncOperation asyncOp)
                   at System.Net.WebClient.DownloadStringAsync(Uri address, Object userToken)
                   at System.Net.WebClient.DownloadStringAsync(Uri address)
                   at OddballHttp.MainPage.MainPage_Loaded(Object sender, RoutedEventArgs e)
                   at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
                   at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)
Jon Rea
  • 9,337
  • 4
  • 32
  • 35