3

I have created a post method for sending json like below.,

daywiseInventory Page C# -

public string daywiseInventory(string JsonQuery)
{
    try
    {
        var httpWebRequest = (HttpWebRequest)WebRequest.Create("www.example.com/booking.aspx");
        httpWebRequest.ContentType = "text/json";
        httpWebRequest.Method = "POST";

        using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
        {
            string json = JsonQuery;

            streamWriter.Write(json);
        }
        var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
        using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
        {
            var responseText = streamReader.ReadToEnd();
            return responseText;
        }
    }
    catch (Exception ex)
    {
        return ex.Message;
    }
}

And I want to get the posting json in Booking Page_Load. How can i code for this?

when i trying the below code in page_load was not helping. it through Invalid URI: The URI is empty Error.

HttpWebRequest webRequest = WebRequest.Create ("") as HttpWebRequest;
HttpWebResponse response = webRequest.GetResponse () as HttpWebResponse;

// Read the response
StreamReader reader = new StreamReader (response.GetResponseStream ());
var responseText = reader.ReadToEnd ();

I am new to this json. So kindly explain how to get the json string that i have post?

4
  • 2
    Correct content type for json is application/json Commented Jul 11, 2014 at 8:10
  • thanks uriil i will change.. Commented Jul 11, 2014 at 8:53
  • Are you saying that you want the value of JsonQuery in the Page_Load method? Commented Jul 12, 2014 at 10:36
  • s sir. i want the JsonQuery value Commented Jul 14, 2014 at 8:51

1 Answer 1

1

Looking at your code:

HttpWebRequest webRequest = WebRequest.Create ("") as HttpWebRequest;

You haven't specified the Uri in the WebRequest.Create(""), so to correct it, add a URI to connect to.

HttpWebRequest webRequest = WebRequest.Create ("http://my.website.to/connect.to.aspx") as HttpWebRequest;
Sign up to request clarification or add additional context in comments.

4 Comments

I have specify the www.example.com/booking.aspx url in post method. I have return the response too. Is possible to get the json response without specifying the url?
@Sagotharan it's really unclear what you need. Get JSON responce, without sending request?
I am new this sir, so only it get confusing. see my project sir.. drive.google.com/file/d/0B2w9Ww9b3kRvRm15M0VrYVhiRFU/…
i have post a json to www.mcubicsoftware.com/booking.aspx/HttpGet url, and i want get the same json in httpget function sir. It just sending and receiving json string program sir. I have done post method. but i don;t know the get method. is this explanation help understand me sir?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.