I have a Windows Form which submits a POST request to a web server. This will return an url.
Something like this when you do a curl to web server:
curl -d 'info={ "EmployeeID": [ "1234567", "7654321" ], "Salary": true, "BonusPercentage": 10}' http://example.com/xyz/php/api/createjob.php
URL returned:
http://example.com/xyz#newjobapi:id=19
Now I would like to replicate the above process on a windows form which when user clicks the button, it will POST the required information from the Windows form to the server.
But i dont get any response upon clicking the button. It just shows an empty messageBox.
Kindly let me how to display the url returned by the server to the user as a pop up window. Thanks.
My C# Code:
private void button8_Click(object sender, EventArgs e)
{
HttpWebRequest webRequest;
string requestParams = "\'info={ \"EmployeeID\": [ \"1234567\", \"7654321\" ], \"Salary\": true, \"BonusPercentage\": 10}\'";
byte[] byteArray = Encoding.UTF8.GetBytes(requestParams);
webRequest = (HttpWebRequest)WebRequest.Create("http://example.com/xyz/php/api/createjob.php");
webRequest.Method = "POST";
webRequest.ContentType = "application/json";
webRequest.ContentLength = byteArray.Length;
using (Stream requestStream = webRequest.GetRequestStream())
{
requestStream.Write(byteArray, 0, byteArray.Length);
}
// Get the response.
using (WebResponse response = webRequest.GetResponse())
{
using (Stream responseStream = response.GetResponseStream())
{
StreamReader rdr = new StreamReader(responseStream, Encoding.UTF8);
string Json = rdr.ReadToEnd(); // response from server
MessageBox.Show("URL Returned: " + Json);
}
}
}