快速业务通道

CPPWebBrowser的PostData

作者 佚名技术 来源 程序设计 浏览 发布时间 2012-06-29

WideString URL = "http://www.bianceng.cn/maker/pass.asp";;

ParamString = "username=test&password=12345";

TVariant *PostData = new TVariant(ParamString);

CPPWebBrowser->Navigate(URL,0,0,PostData,0);

这样是不行的,网页收不到参数。

http://www.bianceng.cn/maker/pass.asp?username=test&password=12345

这样是可以访问的。

请问该如何设置PostData的值?

给你一个直接Post的函数

如:

WebPostData(CppWebBrowser1,"http://211.91.2.221/pass.asp";

,"test=333333&PassWord=343200");

我试过,可以用

void __fastcall TForm1::WebPostData(TCppWebBrowser *CppWebBrowser, String sURL, String sPostData)
{
BSTR bstrHeaders = NULL;
TVariant vFlags = {0}, vTargetFrameName={0}, vPostData={0}, vHeaders={0};
LPSAFEARRAY psa;
LPCTSTR cszPostData = sPostData.c_str();
UINT cElems = lstrlen(cszPostData);
LPSTR pPostData;
LPVARIANT pvPostData;
bstrHeaders = SysAllocString(L"Content-Type: application/x-www-form-urlencodedrn");
if (!bstrHeaders){
Application->MessageBox("Could not allocate bstrHeaders", "Warning", MB_OK | MB_ICONWARNING);
return;
}
V_VT(&vHeaders) = VT_BSTR;
V_BSTR(&vHeaders) = bstrHeaders;
pvPostData = vPostData;
if(pvPostData){
VariantInit(pvPostData);
psa = SafeArrayCreateVector(VT_UI1, 0, cElems);
if(!psa){
return;
}
SafeArrayAccessData(psa, (LPVOID*)&pPostData);
memcpy(pPostData, cszPostData, cElems);
SafeArrayUnaccessData(psa);
V_VT(pvPostData) = VT_ARRAY | VT_UI1;
V_ARRAY(pvPostData) = psa;
}
CppWebBrowser->Navigate((TVariant)sURL, &vFlags, &vTargetFrameName, &vPostData, &vHeaders);
}
How to post data using TCppWebBrowser in C++Builder (转www.borland.com)
Abstract:This article demonstrates techniques for using the CppWebBrowser component to browse and post data using Navigate and Navigate2 methods. By Adam Vieweger.
I had been tearing my hair out for more than two weeks. I wanted to use the TCppWebBrowser component (distributed with Borland C++Builder starting with BCB 5 Enterprise Edition) to create an app that would browse the Web and allow users to post data to Web pages. I was having a tough time of it because the documentation on TCppWebBrowser is fairly sparse and there aren''t many articles out there to guide me.
So I rolled up my sleeves and started working. I hope my discoveries prove useful to you.
Browsing with CppWebBrowser turned out to be fairly simple. There are two methods that provide browsing capabilities: Navigate and Navigate2:
CppWebBrowser1->Navigate("http://www.inprise.com";)
Navigate2 is extension of Navigate, but practically it does not matter for us -- in this article we can use both of them interchangeably.
Should you want to find more information about WebBrowser component properties, methods, and events, please refer to online MSDN library: http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/webbrowser/reference/Objects/WebBrowser.asp
HARDER PROBLEMS
Posting data proved to be a tougher nut to cra

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号