Note that there are some explanatory texts on larger screens.

plurals
  1. POJSON Data posted by Silverlight is not reaching the server
    primarykey
    data
    text
    <p>I have a web client I'm creating in Silverlight. I am trying to get it to communicate it with my web services on my server through GET and POST requests and JSON. The GET requests work fine and I'm able to parse the JSON on the Silverlight end. The POST requests however dont seem to work. The server reads that there is a POST request, but the POST array is empty.</p> <p>Ive tried two pieces of code to send the POST requests, but both are resulting in the same response - an empty array.</p> <p>The first Silverlight code I tried was:</p> <pre><code> public MainPage() { InitializeComponent(); HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri("http://www.dipzo.com/game/services.php")); request.Method = "POST"; request.ContentType = "application/json"; request.BeginGetRequestStream(new AsyncCallback(OnGetRequestStreamCompleted), request); } private void OnGetRequestStreamCompleted(IAsyncResult ar) { HttpWebRequest request = (HttpWebRequest)ar.AsyncState; using (StreamWriter writer = new StreamWriter(request.EndGetRequestStream(ar))) { writer.Write("name=david"); } request.BeginGetResponse(new AsyncCallback(OnGetResponseCompleted), request); } private void OnGetResponseCompleted(IAsyncResult ar) { //this.GetResponseCoimpleted.Visibility = Visibility.Visible; // Complete the Flickr request and marshal to the UI thread using (HttpWebResponse response = (HttpWebResponse)((HttpWebRequest)ar.AsyncState).EndGetResponse(ar)) { using (StreamReader reader = new StreamReader(response.GetResponseStream())) { string results = reader.ReadToEnd(); } } } </code></pre> <p>The second piece I tried was:</p> <pre><code> private void WebClient_Click(object sender, RoutedEventArgs e) { Test t1 = new Test() { Name = "Civics", Marks = 100 }; DataContractJsonSerializer jsondata = new DataContractJsonSerializer(typeof(Test)); MemoryStream mem = new MemoryStream(); jsondata.WriteObject(mem, t1); string josnserdata = Encoding.UTF8.GetString(mem.ToArray(), 0, (int)mem.Length); WebClient cnt = new WebClient(); cnt.UploadStringCompleted += new UploadStringCompletedEventHandler(cnt_UploadStringCompleted); cnt.Headers["Content-type"] = "application/json"; cnt.Encoding = Encoding.UTF8; cnt.UploadStringAsync(new Uri("http://www.dipzo.com/game/services.php"), "POST", josnserdata); } void cnt_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e) { var x = e; } </code></pre> <p>The code on the server to consume the service is in PHP and is essentially: var_dump($_POST)</p> <p>This should output whatever is coming into the post array. I've tested it with a simple PHP client and it works. Just can't get it to work in silverlight. In silverlight I just keep getting an empty array.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload