C++ Builder编写WinForm Post数据至Web服务器并得到返回数据
时间:2011-04-08 来源:袁晓平
需要用到Indy组件,这个安装了C++Builder就会有,有于服务端是asp.net编写的,有一个隐藏域__VIEWSTATE,所以要加上它,然后再看服务器端需要什么字段就用TStringList对象Add就可以了,具体代码如下:
TIdHTTP *http = new TIdHTTP(NULL);
TStringList *formData = new TStringList();
try{
IdAntiFreeze1->OnlyWhenIdle = false;
formData->Add("act=get_print_content");
formData->Add("ai_id=6656");
formData->Add("pbf_id=2100");
formData->Add("__VIEWSTATE=/wEPDwUJNzgzNDMwNTMzZGSBubljYEzsn5kDlFLpfAY1gf94Mw==");
UnicodeString result = http->Post("http://localhost/shaj.synadmin/inlineadminsite/common/print/PrintWordWin.aspx", formData);
WideString wresult = result;
if (result == "ok") {
//MessageDlg("文件上传成功!", mtInformation, mbOK, 0);
} else {
//MessageDlg("文件上传失败!", mtInformation, mbOK, 0);
}
}__finally{
delete formData;
delete http;
}