locked
Consume restful web service into console app RRS feed

  • Question

  • Hello Guys,

    I use rest sharp to call web services. 

     var client = new RestClient("https://api.portasigma.com/v1/docs/");
                    client.Timeout = 120000; //2 min
                    client.ReadWriteTimeout = 120000;
                    var request = new RestRequest(Method.POST);
                    //header setting
                    request.AddHeader("authorization", "Basic *******");
                    request.AddHeader("accept", "application/json");
                    request.AddHeader("cache-control", "no-cache");
                    //final data
                    request.AddParameter("description", "Simple Invoice Format");
                    request.AddParameter("comments", "Sample Invoice Documents For Testing");
                    request.AddFile("file", filepath);
                    //execute request               
                    IRestResponse response = new RestResponse();
                    response = client.Execute(request);
                    if (response.IsSuccessful)
                    {
                        JObject jObj = JObject.Parse(response.Content);
                        docGuid = jObj["id"].ToString();
                    }
                    else
                    {
                        docGuid = string.Empty;
                    }

    In Above Code I got error when execute this line of code  

    response = client.Execute(request);

    The error is "The Operation has Time out"

    "StatusCode: 0, Content-Type: , Content-Length: 0)"

    I don't Know about this and how to solve this pls suggest me 

    Thanks For Help !!!


    Tuesday, October 6, 2020 10:41 AM

All replies

  • Perhaps https://api.portasigma.com/v1/docs/ timeout because you have no username and password setup for the request.

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, October 6, 2020 1:15 PM
  • Thanks for your reply

    This api uses basic authentication so I create base64 header based on username and password

    I uses  request.AddHeader("authorization", "Basic *******"); this code for authentication

    actually data post successfully https://api.portasigma.com/v1/docs/ on this platform

    but prblm in getting response (this line of code)

    " IRestResponse response = new RestResponse();
      response = client.Execute(request);"

    I do not get response in "response" object error occur here I don't know why response not getting.

    Thanks !!!


    Tuesday, October 6, 2020 1:40 PM
  • RestSharp is a third party library. We only support MS products in the forums. I recommend you get help with their support.

    Michael Taylor http://www.michaeltaylorp3.net

    Tuesday, October 6, 2020 2:39 PM