1
public async String getData()
{
    if (HttpClientWork == false)
    {
        HttpContent content;
        content = new FormUrlEncodedContent(new[]
        {
            new KeyValuePair<string, string>("Data",  StringToEncoding("한글테스트"))
        });

        MediaTypeHeaderValue mediatype = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
        mediatype.CharSet = "euc-kr";
        mediatype.MediaType = "application/x-www-form-urlencoded";

        content.Headers.ContentType = mediatype;

        try
        {

            HttpResponseMessage response = await httpClient.PostAsync("http://~~~~~~~~", content);
            html = StringToEncoding(responseMessage); 
            System.Diagnostics.Debug.WriteLine(html);


            ....
        }
        catch (Exception e)
        {
                ....
            }
    }
    else
    {
        ......

}

StringToEncoding Function Source

public static String StringToEncoding(String str)
{
    Encoding encode = System.Text.Encoding.GetEncoding("euc-kr");
    byte[] byteencode = encode.GetBytes(str);

    return encode.GetString(byteencode, 0, byteencode.Length);
}

But, Receive data from the server.

��������

As above, Korean is broken.

I don't know How to send data which converted euc-kr from utf-8 in httpclient.

4

1 回答 1

0

application/x-www-form-urlencoded,顾名思义,必须在url-encoding中:

HttpUtility.UrlEncode("한글테스트");
于 2012-12-26T12:01:54.677 回答