4

i`m trying to make a webrequest and send a post data in Hebrew but the server side get it like "?????" and not in hebrew.

    WebRequest request = WebRequest.Create(MyserverClient.Url + Constants.TaskUpdatePropertyURL);
((HttpWebRequest)request).AllowAutoRedirect = false;
((HttpWebRequest)request).KeepAlive = true;

request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded;";
request.Headers.Add("Pragma: no-cache");
request.Headers.Add(string.Format("Cookie: {0}", Client.phpId));
    request.Headers.Add(string.Format("requesttoken: {0}", requestToken));

    string postData = "Some Non-english text";      
    using (Stream dataStream = request.GetRequestStream())
{
    byte[] byteArray = Encoding.UTF8.GetBytes(postData);                
    dataStream.Write(byteArray, 0, byteArray.Length);               
    dataStream.Close();
}

    try{
     HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                // Get the stream containing content returned by the server.
         Stream dataStream2 = response.GetResponseStream ();
                // Open the stream using a StreamReader for easy access.
        StreamReader reader = new StreamReader (dataStream2);
                // Read the content. 
        responseFromServer = reader.ReadToEnd ();
    }
 return responseFromServer;

        } 

as i was saying, for a non-english the server get the post data as "???? ???-??????? ????" but i should be "Some Non-english text" any Suggestions??

3 Answers 3

5

try something like this:

StreamReader readStream = new StreamReader (receiveStream, Encoding.UTF8);
Sign up to request clarification or add additional context in comments.

Comments

0

You can use Uri.EscapeDataString(string)

Comments

-1

Maybe this will do the work: in hebrew,

Encoding.GetEncoding(1255)

2 Comments

This one doesn't seem to work properly for me anymore VS 2017 .net4.5
@AltF4_ Yah, this post is from 2014, it's still may work for older versions

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.