0

So on my client (windows phone 8.1 app) I have posted a JSON just for testing, here is the code for this:

    public async void SendJSON()
    {
        try
        {
            string url = "http://posttestserver.com/post.php?dir=karim";

            var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
            httpWebRequest.ContentType = "text/plain; charset=utf-8";
            httpWebRequest.Method = "POST";

            using (var stream = await Task.Factory.FromAsync<Stream>(httpWebRequest.BeginGetRequestStream,
                                                         httpWebRequest.EndGetRequestStream, null))
            {
                //create some json string
                string json = "{ \"my\" : \"json\" }";

                // convert json to byte array
                byte[] jsonAsBytes = Encoding.UTF8.GetBytes(json);

                // Write the bytes to the stream
                await stream.WriteAsync(jsonAsBytes, 0, jsonAsBytes.Length);
            }
        }
        catch(Exception ex)
        {

        }

    }

Now I'm trying to figure out, from the www.myurl.com how would I retrieve what has been posted from the mobile app using a Web Service?

UPDATE

When I debug these lines, it runs perfectly without breaking nor falling within the catch. However when looking at where it should post to (the results are here http://www.posttestserver.com/data/2015/12/14/karim/) it doesn't post anything.

Does anyone know what I'm doing wrong?

BTW: it already has results there because I have done this directly from my desktop.

KTOV
  • 559
  • 3
  • 14
  • 39

3 Answers3

0

If you just want to see, what have you send, you can use this http://posttestserver.com

Otherwise there is not easy way how to force some endpoint to retrieve data. There must but set up server, which is allowing it, proccessing it, storing it etc.


If you POST anything to http://posttestserver.com/post.php it will return you this message

Successfully dumped 0 post variables. View it at http://www.posttestserver.com/data/2015/12/15/00.19.29177030164 Post body was 134 chars long.

So just print somewhere your response and you will get the exact url

libik
  • 22,239
  • 9
  • 44
  • 87
0

Not sure what you are trying to do but if you want to inspect your http requests fiddler is a good choice. Since your are using windows phone apps you can configure the windows phone emulator to proxy through fiddler.

Here is a blog post how to set this up: http://blogs.msdn.com/b/wsdevsol/archive/2013/06/05/configure-the-windows-phone-8-emulator-to-work-with-fiddler.aspx - Configure the Windows Phone 8 Emulator to work with Fiddler

// Edit: Have you considered to use HttpClient

var httpClient = new HttpClient(); 
string resourceAddress = "http://posttestserver.com/post.php?dir=karim"; 
            string postBody = "{ \"my\" : \"json\" }"
            httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); 
            var response = await httpClient.PostAsync(resourceAddress, new StringContent(postBody, Encoding.UTF8, "application/json")); 

Code is from the top of my head so you might have to tweak it... and of course you need to handle error cases and/or retry, etc HTH

silverfighter
  • 6,762
  • 10
  • 46
  • 73
-1

You should use fiddler to see the outputted content: http://www.telerik.com/fiddler

Windows Phone 8.1 Emulator not proxying through Fiddler

Community
  • 1
  • 1