55143681 Posted November 29, 2020 Posted November 29, 2020 Dear: I user xe10.3.3 to develop a http pos interface, In my VCL APPLICATION,my project works well,the remote host can receive the right message without encoding problem, first I call AnsiToUtf8,then I call IdHTTP1->post the data,and IdHTTP1 have be set forceParamsEncode。 But when I use the same code in UNIGUI,the remote host receive the message,but the message is confusion codes. why? How to send a message like this with c++builder? String myStr:='你好hello'; HTTPEncode(AnsiToUtf8(myStr)); String __fastcall TFormMain::sendHangxin(String destUrl,String sendNo,String userNo,String corpNo,String sendInfo) { /* 调用行信推送消息 */ String dataStr="sendNo="+sendNo+"&userNo="+userNo+"&corpNo="+ corpNo+"&sendInfo="+sendInfo;; TStringStream *postData=new TStringStream(dataStr,TEncoding::UTF8,true); TStringStream *respData=new TStringStream(); IdHTTP1->ReadTimeout=5000;//5秒 IdHTTP1->Request->ContentType="application/x-www-form-urlencoded"; IdHTTP1->Request->Accept="application/json"; IdHTTP1->Post(destUrl,postData,respData); Memo1->Lines->Add(dataStr); Memo2->Lines->Add(Utf8ToAnsi(respData->DataString)); delete postData; delete respData; } Quote
55143681 Posted November 29, 2020 Author Posted November 29, 2020 5 hours ago, 55143681 said: Dear: I user xe10.3.3 to develop a http pos interface, In my VCL APPLICATION,my project works well,the remote host can receive the right message without encoding problem, first I call AnsiToUtf8,then I call IdHTTP1->post the data,and IdHTTP1 have be set forceParamsEncode。 But when I use the same code in UNIGUI,the remote host receive the message,but the message is confusion codes. why? How to send a message like this with c++builder? String myStr:='你好hello'; HTTPEncode(AnsiToUtf8(myStr)); String __fastcall TFormMain::sendHangxin(String destUrl,String sendNo,String userNo,String corpNo,String sendInfo) { /* 调用行信推送消息 */ String dataStr="sendNo="+sendNo+"&userNo="+userNo+"&corpNo="+ corpNo+"&sendInfo="+sendInfo;; TStringStream *postData=new TStringStream(dataStr,TEncoding::UTF8,true); TStringStream *respData=new TStringStream(); IdHTTP1->ReadTimeout=5000;//5秒 IdHTTP1->Request->ContentType="application/x-www-form-urlencoded"; IdHTTP1->Request->Accept="application/json"; IdHTTP1->Post(destUrl,postData,respData); Memo1->Lines->Add(dataStr); Memo2->Lines->Add(Utf8ToAnsi(respData->DataString)); delete postData; delete respData; } #include "System.NetEncoding.hpp" String myStr="adffad": TNetEncoding::URL->Encode(myStr); Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.