Skip to main content
Solved

Using HTTPCaller with Body


nedwaterman
Contributor
Forum|alt.badge.img+9

HI,

 

I've not used the HTTPCaller using a POST request and body attribution.

The API call constructed by the developer has been provided like this:

var client = new RestClient("https://sww.smartchartapi.co.uk/api/Authentication/request");

client.Timeout = -1;

var request = new RestRequest(Method.POST);

request.AddHeader("Content-Type", "application/json");

request.AddHeader("Cookie", "ASP.NET_SessionId=xcqkvogm2bp2yxshsgx1ncbg; AspxAutoDetectCookieSupport=1; __AntiXsrfToken=e680dfae824a472088c01d6672ba8471");

var body = @"{

" + "\\n" +

@"  ""username"": ""SWWAPI"",

" + "\\n" +

@"  ""password"": ""***""

" + "\\n" +

@"}";

request.AddParameter("application/json", body,  ParameterType.RequestBody);

IRestResponse response = client.Execute(request);

Console.WriteLine(response.Content);

 

I've set up the HTTP caller like this but am getting a bad result. Any ideas what I am doing wrong?

 

Capture2Capture

Best answer by sigtill

Might use the https://jsonlint.com/ service to try to create a valid Json for your body. For instance it seems it might be:

 

{

"username": "SWWAPI",

"password": "***"

}

View original
Did this help you find an answer to your question?

4 replies

sigtill
Contributor
Forum|alt.badge.img+24
  • Contributor
  • August 2, 2021

Try to replace the BODY with one line withouth newlines:

{" + "\\n" + @"  ""username"": ""SWWAPI"", " + "\\n" + @"  ""password"": ""***"" " + "\\n" +@"}

 

what is the error message?


sigtill
Contributor
Forum|alt.badge.img+24
  • Contributor
  • Best Answer
  • August 2, 2021

Might use the https://jsonlint.com/ service to try to create a valid Json for your body. For instance it seems it might be:

 

{

"username": "SWWAPI",

"password": "***"

}


nedwaterman
Contributor
Forum|alt.badge.img+9
  • Author
  • Contributor
  • August 2, 2021
sigtill wrote:

Might use the https://jsonlint.com/ service to try to create a valid Json for your body. For instance it seems it might be:

 

{

"username": "SWWAPI",

"password": "***"

}

I'm getting

HTTP/1.1 400 Bad Request - https://sww.smartchartapi.co.uk/api/Authentication/request

 

tried the one line for the body but no joy so I'll try constructing some JSON!


nedwaterman
Contributor
Forum|alt.badge.img+9
  • Author
  • Contributor
  • August 2, 2021
sigtill wrote:

Might use the https://jsonlint.com/ service to try to create a valid Json for your body. For instance it seems it might be:

 

{

"username": "SWWAPI",

"password": "***"

}

Worked" Created valid JSON and passed it using the correct Content type. Thank you!


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings