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 関数のソース

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);
}

ただし、サーバーからデータを受信します。

��������

上記のように、韓国語は壊れています。

httpclient で euc-kr を utf-8 に変換したデータの送信方法がわかりません。

4

1 に答える 1