Click here to Skip to main content
15,898,010 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
<form method="post" action="http://pudhukadai.co.in/api/bus/search_trip.php">
<textarea name="request">
{"uid": "xxxx","pin": "xxxx","source_id": "1270","destination_id": "323","date": "05-05-2017"}
</textarea>
 
 <input type="submit" name="submit" value="submit">
</form>


What I have tried:

WebRequest request = (WebRequest)WebRequest.Create("http://pudhukadai.co.in/api/bus/search_trip.php?uid=xxxx&pin=xxxx&source_id=1270&destination_id=323&date=25-04-2017");
request.Method = "post";
request.ContentType = "application/json; charset=utf-8";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string result = reader.ReadToEnd();
Posted
Updated 17-May-17 11:01am
Comments
j snooze 11-May-17 17:31pm    
I'm guessing you need to post the data vs sending it as part of the URL.
If you made a trip object made up of the uid, pin, source_id,destination_id,date
you could set those
trip.uid=xxxxxx;
trip.pin=xxxxxx;
along with the other properties.
then try this

var baseAddress = "http://pudhukadai.co.in/api/bus/search_trip.php";
string serialObject = JsonConvert.SerializeObject(trip);

var http = (HttpWebRequest)WebRequest.Create(new Uri(baseAddress));
http.Accept = "Accept=application/json";
http.ContentType = "application/json";
http.Method = "POST";
http.SendChunked = false;

http.ContentLength = serialObject.Length;
using (var writer = new StreamWriter(http.GetRequestStream()))
{
writer.Write(serialObject);
}
var response = http.GetResponse() as HttpWebResponse;

1 solution

string json = "{\"uid\": \"xxxx\",\"pin\": \"xxxx\",\"source_id\": \"1270\",\"destination_id\": \"323\",\"date\": \"05-05-2017\"}";
var httpContent = new StringContent(json, Encoding.UTF8, "application/json");
using (var httpClient = new HttpClient())
{
    // Error here
    var httpResponse = await httpClient.PostAsync("http://pudhukadai.co.in/api/bus/search_trip.php", httpContent);
    if (httpResponse.Content != null)
    {
        // Error Here
        var responseContent = await httpResponse.Content.ReadAsStringAsync();
    }
}

and you may want to look at Newtonsoft.Json to handle creating the Json string.
 
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