用c写了一个向sohu微博发信息的程序,不知为什么发中文时总是乱码?
int CWeiboSohu::SendMsg(char *szMsg)
{
//
////////////////////////////////////////////////////////////////
char *pCode = FormUrlEncode(szMsg);
char* pUtf8 = MbcsToUtf8(pCode);
////////////////////////////////////////////////////////////////
char szUrl[1024] = "http://api.t.sohu.com/statuses/update.json?source=UGKujfSYomAjKkIcgbbu&status=";
strcat(szUrl, pUtf8); //hiiii111222";
//
CURL *curl;
CURLcode res;
//
curl = curl_easy_init();
//
if(curl){
//
curl_easy_setopt(curl, CURLOPT_POST, 1 );
curl_easy_setopt(curl, CURLOPT_URL, "http://api.t.sohu.com/statuses/update.json");
//curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_easy_setopt(curl, CURLOPT_USERPWD, "Name:Password");
//
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, szUrl);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(szUrl));
//
res = curl_easy_perform(curl);
// always cleanup
curl_easy_cleanup(curl);
}
return 0;