Results 1 to 4 of 4

Thread: A bug of Spring REST Client 1.0: Silverlight don't allow to custom HEADER when GET

  1. #1
    Join Date
    Jun 2011
    Posts
    2

    Post A bug of Spring REST Client 1.0: Silverlight don't allow to custom HEADER when GET

    I try:
    Code:
    RestTemplate rt = new RestTemplate("http://localhost:8080");
                rt.MessageConverters.Add(new XElementHttpMessageConverter());
                rt.GetForMessageAsync<XElement>("/modelbuilder/services/modeldefine", r =>
                    {
                        if (r.Error == null)
                        {
                            Debug.WriteLine(r.Response.Body.ToString());
                        }
                        else
                        {
                            Debug.WriteLine(r.Error);
                        }
                    });
    Result:
    Code:
    System.NotSupportedException ---> System.NotSupportedException: 不支持所指定的方法。
       位于 System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
       位于 System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClass5.<EndGetResponse>b__4(Object sendState)
       位于 System.Net.Browser.AsyncHelper.<>c__DisplayClass4.<BeginOnUI>b__1(Object sendState)
       --- 内部异常堆栈跟踪的结尾 ---
       位于 System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
       位于 System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
       位于 Spring.Http.Client.WebClientHttpRequest.ExecuteResponseCallback(IAsyncResult result)
    I google:
    Silverlight only supports setting headers using the POST method not the GET method.
    So add some code to "ExecuteAsync" of "WebClientHttpRequest.cs"

    Code:
    // Prepare
                    if (this.Method != HttpMethod.GET)
                    {
                        this.PrepareForExecution();
                    }
    All ok.

  2. #2
    Join Date
    Oct 2005
    Location
    Toulouse, France
    Posts
    1,407

    Default

    Hi,

    This is the default .NET behavior see :
    http://msdn.microsoft.com/en-us/libr...(v=VS.96).aspx

    To make this work, you need to change to Client HTTP handling :
    Code:
    ((WebClientHttpRequestFactory)rt.RequestFactory).WebRequestCreator = WebRequestCreatorType.ClientHttp;

    - Bruno
    My english is as poor as my taylor is rich

  3. #3
    Join Date
    Jun 2011
    Posts
    2

    Default

    Thank you, Bruno Baia.

    Could you change the default setting for Silverlight?
    It will be more pleasure for beginners.

  4. #4
    Join Date
    Oct 2005
    Location
    Toulouse, France
    Posts
    1,407

    Default

    Hi,

    I detected a bug, on a windows phone project, that can be related to your case :
    https://jira.springsource.org/browse/SPRNETREST-4

    I don't think we should change the default behavior to remain consistent with Microsoft implementation.
    I will document use of Browser or Client HTTP Handling for silverlight applications :
    https://jira.springsource.org/browse/SPRNETREST-5


    - Bruno
    My english is as poor as my taylor is rich

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •