Issue After upgrading Restsharp version

Viewed 60

Can someone please help on this issue, i gets hang and no error is coming. Seems like ends up with some unknow issue. I am attaching my code before and after upgrading the restsharp library.

Code in Rest sharp version 106.12.00

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RestSharp;

namespace ConsoleApp5
{
    class Program
    {
        static void Main(string[] args)
        {

            var client = new RestClient("https://shoonyatrade.finvasia.com/NorenWClientTP/QuickAuth");
            client.Timeout = -1;
            var request = new RestRequest(Method.POST);
            request.AddHeader("Content-Type", "text/plain");
            var body = @"jData={""apkversion"":""1.0.0"",""uid"":""123456""}";
            request.AddParameter("text/plain", body, ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            Console.WriteLine(response.Content);
        }
    }
}

Code after upgrading to 108.0.1

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RestSharp;

namespace ConsoleApp5
{
    class Program
    {
        static void Main(string[] args)
        {

            var client = new RestClient("https://shoonyatrade.finvasia.com/NorenWClientTP/QuickAuth");
            client.Options.MaxTimeout = -1;
            var request = new RestRequest("",Method.Post);
            request.AddHeader("Content-Type", "text/plain");
            var body = @"jData={""apkversion"":""1.0.0"",""uid"":""123456""}";
            request.AddParameter("text/plain", body, ParameterType.RequestBody);
            RestResponse response = client.Execute(request);
            Console.WriteLine(response.Content);
        }
    }
}

enter image description here

Expected Response

{"stat":"Not_Ok","emsg":"Invalid Input :  uid or pwd or factor2 or imei or apkversion or vc or appkey or source is Missing."}

Postman Authorisation enter image description here

Postman Headers enter image description here

PostMan Results (Expected)

enter image description here

2 Answers

The docs clearly say that you should not use AddParameter with content-type as the parameter name. It won't work.

Use AddStringBody as described in the docs.

request.AddStringBody(body, "text/plain);

You would spend way less time figuring out what's wrong by sending requests to something like requestbin.com and analysing the actual content of it.

Adding this line solved my issue

System.Net.ServicePointManager.Expect100Continue = false;

I have used fiddler to understand what actual request is going on web.

using RestSharp;
using System;

using System.Net.Http;

using System.Text;

using System.Threading.Tasks;


namespace ConsoleApp5
{
    class Program
    {
        static async Task Main(string[] args)
        {
            System.Net.ServicePointManager.Expect100Continue = false;
            var client = new RestClient("https://shoonyatrade.finvasia.com/NorenWClientTP/QuickAuth");
            var request = new RestRequest("",Method.Post);
            var body = @"jData={""apkversion"":""1.0.0"",""uid"":""123456""}";
            request.AddParameter("text/plain", body, ParameterType.RequestBody);
            RestResponse response = client.Execute(request);
            Console.WriteLine(response.Content);
        }
    }
}
Related