RestClient receiving no reponse

Gerald Oakham 101 Reputation points
2021-07-07T16:04:03.177+00:00

Hello,
I have copied the RestSharp code from POSTMAN into a c# console application, but I am getting no response back (where POSTMAN was working fine).
If I copy the URL into a browser, I get a JSON (error) response, so I am not sure what I am doing wrong, so was hoping someone might be able to spot it and advise me?

When I put the URL in the browser, I (correct) get the following back (so machine can see the URL ok

{  
  "status" : 400,  
  "code" : 40001,  
  "resource" : null,  
  "properties" : [ ],  
  "message" : "The Date header is invalid.",  
  "developerMessage" : "The Date header is invalid. Make sure that a the Date or X-Aah-Date header is set and has a valid format."  
}  

when I use the code from POSTMAN in a console application :

string rgn = "GMT ";  
curntdateStr= DateTime.Now.ToString("ddd, dd MMM yyyy HH:mm:ss ");  
curntdateStr = curntdateStr +rgn;  
  
//Get Local PC name  
string strComputerName = Environment.MachineName.ToString();  
System.IO.File.AppendAllText(cutCardspath, Environment.NewLine+ "*** Machine " + strComputerName + " requested " + args[4] + " items for " + args[0] + " at " + DateTime.Now + " form " + args[1] + " to " + args[2] + " on " + usedevice + " for id "+ args[3] + "."+ Environment.NewLine);  
  
var resclient = new RestClient(useIP);  
resclient.Timeout = -1;  
var request = new RestRequest(Method.POST);  
request.AddHeader("Content-MD5", "T9jrc45PQQ4oFU0JbLnNQw==");  
request.AddHeader("Date", curntdateStr);  
request.AddHeader("X-Aah-Date", curntdateStr);  
request.AddHeader("Content-Type", "application/json;charset=UTF-8");  
request.AddHeader("Cookie", "JSESSIONID=A6E20F1F32D9FEB0D4A5DB11DB7597e7");  
var body = @"{" + "\n" + @"  ""username"": " + "\"" + usr + "\"" + "," + "\n" + @"  ""password"": " + "\"" + pword + "\"" + "" + "\n" + @"}";  
 request.AddParameter("application/json;charset=UTF-8", body, ParameterType.RequestBody);  
IRestResponse response = resclient.Execute(request);  
Console.WriteLine(">>> " +response.Content);  
Console.ReadLine();  

I receive no response to output

Can anyone see what I am doing incorrectly / need to do read the response back ?

thank you

.NET CLI
.NET CLI
A cross-platform toolchain for developing, building, running, and publishing .NET applications.
326 questions
{count} votes