CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2009
    Posts
    177

    RestSharp Passing Parameter to Web Api

    Hi,

    I had the following code to call my webApi.

    Code:
     public EFileInfo UploadFile(string WebApiBaseAddress, string WebApiServiceUrl, WebApiParameters webParams)
                {
                    EFileInfo eFile = null;
    
                    RestClient client = new RestClient(WebApiBaseAddress);
                    RestRequest  request = new RestRequest(WebApiServiceUrl, Method.POST);
                    request.RequestFormat = DataFormat.Json;
                    request.AddBody(webParams);
    
                    IRestResponse response = client.Execute(request);
    
                    eFile = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<EFileInfo>(response.Content);
    
                    return eFile;
                }
    It seems like I am unable to pass the WebParams to my WebApi. My WebParams consists of multiple different type parameter as below:

    Code:
         public class UploadFileInfo {
            public UploadFileInfo() {
                ContentType = "application/octet-stream";
            }
            public string Name { get; set; }
            public string FileName { get; set; }
            public string ContentType { get; set; }
            public byte[] ByteArray { get; set; }
    
        }
    
        public class WebApiParameters {
            public IDictionary<string, string> Parameters { get; set; }
            public IEnumerable<UploadFileInfo> UploadFiles { get; set; }
    
        }

    How can I add my parameter into my RestClient and pass it to WebApi?

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: RestSharp Passing Parameter to Web Api

    I did a bing search for "Post parameters to RestClient" and came up with.

    http://stackoverflow.com/questions/1...ost-parameters

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured