Click here to Skip to main content
16,022,069 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi guys

i have a basic request to a website and here is the website jason :

login_id: Ashkinx
csrf_token: eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiJkZGJlMTFkOC0yY2RkLTQ2ZGEtYTBhNS05ZTRhZmZjYTNkNmUiLCJpc3MiOiJodHRwczovL2FjY291bnRzLm5pbnRlbmRvLmNvbSIsImlhdCI6MTcyMjg2NDA0NiwiZXhwIjoxNzIyODY3NjQ2LCJfZXh0Ijp7InAiOnt9LCJ0IjoiNTUzODIwMjU1IiwiYSI6ImFjY291bnRzX2xvZ2luX2lkX2VkaXRfZm9ybSJ9LCJ0eXAiOiJjc3JmX3Rva2VuIiwic3ViIjoiMzNlNDE5Yjg2ZGY3M2VmMSJ9.0WTIRb-TeoNX905yLkAD-MQBrUpXBsHlPnhbqEZD2to


butwhen i send a post in C# it won't successful

i monitor it with Fidler and here is my jason when it post :

{"login_id":"AshkinX","csrf_token":"eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiJkZGJlMTFkOC0yY2RkLTQ2ZGEtYTBhNS05ZTRhZmZjYTNkNmUiLCJpc3MiOiJodHRwczovL2FjY291bnRzLm5pbnRlbmRvLmNvbSIsImlhdCI6MTcyMjg2NDA0NiwiZXhwIjoxNzIyODY3NjQ2LCJfZXh0Ijp7InAiOnt9LCJ0IjoiNTUzODIwMjU1IiwiYSI6ImFjY291bnRzX2xvZ2luX2lkX2VkaXRfZm9ybSJ9LCJ0eXAiOiJjc3JmX3Rva2VuIiwic3ViIjoiMzNlNDE5Yjg2ZGY3M2VmMSJ9.0WTIRb-TeoNX905yLkAD-MQBrUpXBsHlPnhbqEZD2to"}


but the website jason when i try manually is this :
login_id=AshkinX&csrf_token=eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiJkZGJlMTFkOC0yY2RkLTQ2ZGEtYTBhNS05ZTRhZmZjYTNkNmUiLCJpc3MiOiJodHRwczovL2FjY291bnRzLm5pbnRlbmRvLmNvbSIsImlhdCI6MTcyMjg2NDA0NiwiZXhwIjoxNzIyODY3NjQ2LCJfZXh0Ijp7InAiOnt9LCJ0IjoiNTUzODIwMjU1IiwiYSI6ImFjY291bnRzX2xvZ2luX2lkX2VkaXRfZm9ybSJ9LCJ0eXAiOiJjc3JmX3Rva2VuIiwic3ViIjoiMzNlNDE5Yjg2ZGY3M2VmMSJ9.0WTIRb-TeoNX905yLkAD-MQBrUpXBsHlPnhbqEZD2to




any help ?

What I have tried:

var newPost = new Post()
             {


                 login_id = "AshkinX",
                 csrf_token = "eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiJkZGJlMTFkOC0yY2RkLTQ2ZGEtYTBhNS05ZTRhZmZjYTNkNmUiLCJpc3MiOiJodHRwczovL2FjY291bnRzLm5pbnRlbmRvLmNvbSIsImlhdCI6MTcyMjg2NDA0NiwiZXhwIjoxNzIyODY3NjQ2LCJfZXh0Ijp7InAiOnt9LCJ0IjoiNTUzODIwMjU1IiwiYSI6ImFjY291bnRzX2xvZ2luX2lkX2VkaXRfZm9ybSJ9LCJ0eXAiOiJjc3JmX3Rva2VuIiwic3ViIjoiMzNlNDE5Yjg2ZGY3M2VmMSJ9.0WTIRb-TeoNX905yLkAD-MQBrUpXBsHlPnhbqEZD2to",


             };

var NewPostJson = JsonConvert.SerializeObject(newPost);
                  var content = new System.Net.Http.StringContent(NewPostJson, Encoding.UTF8, "application/json");
                  var result = client.PostAsync(url, content).Result.Content.ReadAsStringAsync().Result;
Posted

Looking at the content that you successfully managed to post across indicates that you aren't actually expecting a JSON payload at the endpoint. That looks suspiciously like a URL there. You need to look at the documentation for the site to see what they are expecting here because you can't just send requests across in random formats and expect them to cope.

So, this is what you do. You read the documentation to find out what the website is expecting - we can't do this for you as we have no idea which site it is, or what operation you are attempting to perform. Then you try out what the site expects; if you have problems at that point, come back to us with more details about what the endpoint is doing; the details of the operation that the site expects, and so on.
 
Share this answer
 
It seems the web API is a GET endpoint but you're attempting POST a request.  What is the HTTP status of your POST request?  I assume it will be 404 because the GET endpoint doesn't exist.

I expect you'll need to send a GET request in order for the endpoint to return the expected result.

/ravi
 
Share this answer
 
Those usually go in the header. Please check the API documentation.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900