Archived Forum Post

Index of archived forum posts

Question:

how to post login website with username utf8 char

Jul 05 '15 at 10:55

i have username: cuộc tình and can not post to login web site because chilkat encode username difirent with Live HTTP Headers

log post data chilkat

vb_login_username=cu%2526%25237897%253Bc%2Bt%25ECnh&vb_login_password_hint=Password&vb_login_password=123456&s=5730fcbc71c73e159460dcaaba30c647&securitytoken=guest&do=login&vb_login_md5password=e10adc3949ba59abbe56e057f20f883e&vb_login_md5password_utf=e10adc3949ba59abbe56e057f20f883e&s=5730fcbc71c73e159460dcaaba30c647&do=login

log postdata live HTTP Headers

vb_login_username=cu%26%237897%3Bc+t%ECnh&vb_login_password_hint=Password&vb_login_password=123456&s=5730fcbc71c73e159460dcaaba30c647&securitytoken=guest&do=login&vb_login_md5password=e10adc3949ba59abbe56e057f20f883e&vb_login_md5password_utf=e10adc3949ba59abbe56e057f20f883e

my code

Chilkat.HttpRequest post = new Chilkat.HttpRequest();
        post.AddParam("vb_login_username", "cuộc tình");
        post.AddParam("vb_login_password_hint", "Password");
        post.AddParam("vb_login_password", "123456");
        post.AddParam("s", "5730fcbc71c73e159460dcaaba30c647");
        post.AddParam("securitytoken", "guest");
        post.AddParam("do", "login");
        post.AddParam("vb_login_md5password", "e10adc3949ba59abbe56e057f20f883e");
        post.AddParam("vb_login_md5password_utf", "e10adc3949ba59abbe56e057f20f883e");
        post.HttpVerb = "POST";
        post.UsePost();
        Chilkat.HttpResponse html = http.PostUrlEncoded("http://forums.vwvortex.com/login.php?s=5730fcbc71c73e159460dcaaba30c647&do=login", post);
        string htmlretur = html.BodyStr;
        http.SendCookies = true;
        richTextBox1.Text = htmlretur;

Answer

Maybe the Charset property will do the trick? e.g. post.Charset = "utf-8"

From the documentation:

Charset As String

Controls the character encoding used for HTTP request parameters for POST requests. The default value is the ANSI charset of the computer. The charset should match the charset expected by the form target.

The "charset" attribute is only included in the Content-Type header of the request if the SendCharset property is set to 1.


Answer

Hi thanh858036 (& jpbro),

Fyi, few days back I tried to POST Chinese character string in one of the param. You may search for my query in this forum. I am able to send UTF-8 string partially successfully (odd number of chinese characters was sent Empty !!!). Even number of Chinese characters without issue..strange ...

However, after reading the above tip from jbpro (Hi jpbro, Thanks again !)...It works beautifully for my case without the need to use Ckstring !

Below is my VC code, hope that it will help you....

BengRequest.put_HttpVerb("POST");

BengRequest.put_Path("/login.php");

BengRequest.put_Charset("utf-8"); // *** Magic tip ! ****

BengHttp.put_RedirectVerb("");

BengRequest.AddHeader("Accept","application/json, text/javascript, /; q=0.01");

BengRequest.AddHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");

BengRequest.AddHeader("X-Requested-With","XMLHttpRequest");

BengRequest.AddHeader("Referer","http://www.xxxxxx.com/");

BengRequest.AddHeader("Accept-Language","zh-CN");

BengRequest.AddHeader("User-Agent","Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko");

BengRequest.AddHeader("Connection","Keep-Alive");

BengRequest.AddHeader("Host",szDomain);

BengRequest.AddHeader("Pragma","no-cache");

BengRequest.AddParam("act","login");

BengRequest.AddParam("tbUserAccount",szUserAccount);

BengRequest.AddParam("tbUserPwd",szUserPwd);

BengRequest.AddParam("tbCode","");

BengRequest.AddParam("nextAutoLogin","1");

BengRequest.AddParam("re","http://www.xxxxxxxx.com");

BengResponse = BengHttp.SynchronousRequest(szDomain,80,false,BengRequest);

That's all.

Best regards Dragon


Answer

i set charset utf-8 but can not login success

Chilkat.HttpRequest post = new Chilkat.HttpRequest();
    post.Charset = "utf8";// added utf-8
    post.AddParam("vb_login_username", "cuộc tình");
    post.AddParam("vb_login_password_hint", "Password");
    post.AddParam("vb_login_password", "123456");
    post.AddParam("s", "5730fcbc71c73e159460dcaaba30c647");
    post.AddParam("securitytoken", "guest");
    post.AddParam("do", "login");
    post.AddParam("vb_login_md5password", "e10adc3949ba59abbe56e057f20f883e");
    post.AddParam("vb_login_md5password_utf", "e10adc3949ba59abbe56e057f20f883e");
    post.HttpVerb = "POST";
    post.UsePost();
    Chilkat.HttpResponse html = http.PostUrlEncoded("http://forums.vwvortex.com/login.php?s=5730fcbc71c73e159460dcaaba30c647&do=login", post);
    string htmlretur = html.BodyStr;
    http.SendCookies = true;
    richTextBox1.Text = htmlretur;

Answer

who can help me please