0

I am developing windows phone app. In that i need to send a json string to the server in UTF8 encoded format. I follow the below mentioned method.

    private void RequestStreamCallBack(IAsyncResult ar)
    {
        try
        {
            HttpWebRequest request = (HttpWebRequest)ar.AsyncState;

            Stream postStream = request.EndGetRequestStream(ar);

            string postData = "OPERATION_NAME=" + operationName + "&INPUT_DATA=" + inputData ;

            byte[] byteArray = Encoding.UTF8.GetBytes(postData);

            postStream.Write(byteArray, 0, postData.Length);
            postStream.Close();

            request.BeginGetResponse(new AsyncCallback(ResponseCallback), request);
        }
        catch (Exception ex)
        {
        }
    }

The inputData contains the JSON string. So far it worked perfectly. But now the json string has " " character or "+" character. When these characters are present the server is not giving expected response. i don't know what I'm missing.

Please help. Thank you.

Presse
  • 418
  • 1
  • 4
  • 23

1 Answers1

1

PostData when submitted in application/x-www-urlencoded format must be URL Encoded.

It's in the name.

string postData = "OPERATION_NAME=" + URLEncode(operationName)
    + "&" + "INPUT_DATA=" + URLEncode(inputData);
Ben
  • 34,935
  • 6
  • 74
  • 113
  • It's right [here](http://msdn.microsoft.com/en-us/library/zttxte6w(v=vs.110).aspx) – Sven Grosen Mar 21 '14 at 13:39
  • Thanks it helps. But as i am developing in windows phone, I found that I have to use the native classes. Uri.EscapeDataString instead of URLEncode. Thanks although. [link](http://stackoverflow.com/questions/2573290/httputility-urlencode-in-windows-phone-7) – Presse Mar 21 '14 at 13:46