I'm a bit clueless on this so please excuse my lack of code examples.
Basically I've got a requirement to pass in a json 'string' array to a php page which in turn should give me back a response.
so firstly I need to create a string and serialize (?) this into a json object and pass it to a specified url....so firstly I'm not sure that I'm going about this in the correct way and then pass this to a URL:
protected void cmdConnect_Click(object sender, EventArgs e)
{
var sig = FormsAuthentication.HashPasswordForStoringInConfigFile(DateTime.Now.ToString("yyyy-MM-dd") + "!Cv*z]&z7:c,+zW", "SHA1");
var model = "Array (shortened for ease))";
var json = JsonConvert.SerializeObject(model);
string data = HttpUtility.UrlEncode(json);
byte[] byteArray = System.Text.Encoding.ASCII.GetBytes(data);
curlPost(data);
//jsonString.Text = json;
}
protected void curlPost(string data)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://dev.com/shopping_cart.php");
request.Method = "POST";
request.ContentType = "application/json";
byte[] buffer = UTF8Encoding.UTF8.GetBytes(data);
request.ContentLength = buffer.Length;
using (Stream oStream = request.GetRequestStream())
{
oStream.Write(buffer, 0, buffer.Length);
}
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
var reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
string myResponse = reader.ReadToEnd();
jsonString.Text = myResponse;
}
}
But although I'm getting a response (myResponse) the data that I'm passing in has no impact on it so I'm thinking that I'm either not constructing it properly or I'm not passing it in at all. What I should get back is a 'key' but what I'm actually getting back is the HTML for the php page.
I know that this is really vague but a) this is all brand new to me and b) as such I'm not sure that of the terminology involved.
Any pointers would be greatly appreciated.
Thanks, Craig