DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
lazarus/fpc/Free Pascal
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: eyang11
今日帖子: 1
在线用户: 3
导航: 论坛 -> DELPHI技术 斑竹:liumazi,sephil  
作者:
男 z41800 (ok) ★☆☆☆☆ -
盒子活跃会员
2004/5/8 7:31:51
标题:
用什么控件可以向网络递交数据! 浏览:2139
加入我的收藏
楼主: 大家都知道信息发布网站,我想做一个用程序向这些常用的网站递交数据,我每天在一些常用的网站上发信息太累了,想用程序做一个,不知什么控件可以。请高手指点!
----------------------------------------------
-
作者:
男 luckypig (luckypig) ★☆☆☆☆ -
盒子活跃会员
2004/5/8 10:06:11
1楼: 不用控件的。
自己写就可以了。

你得分析一下你要提交信息的那个网站的提交表单,通常表单提交是一个ASP或是CGI或是PHP的页面,你在自己的程序中填上不同的参数即可了。
----------------------------------------------
-
作者:
男 bren (冰人) ★☆☆☆☆ -
普通会员
2004/5/8 11:02:05
2楼: 晕呀!那你可以用clinetsock控件呀!传送信息,要知道对方的主机名或者IP,和端口号,这是必要的

----------------------------------------------
---------------------------
||||知已知彼,百战不殆!|||||
---------------------------
努力学习,天天向上!
                          -----------冰人吻语
                          IP:xxx.xxx.xxx.xxx
作者:
男 z41800 (ok) ★☆☆☆☆ -
盒子活跃会员
2004/5/8 11:33:52
3楼: 我分析了表单
是这样的
www.dygx.gov.cn/gq/addmed.asp?n=15&t1=/title/&t2=/email/&t5=/conne/&t4=/qh/-/telpho/&d1=/zpriva/&d2=99999&B1=马上发布

title是信息标题
email是邮件地址
conne是信息内容
qh是区号
telpho是电话号码
zpriva是省份

如果里面的变量有汉字替换,直接在IE地址栏上就可以发到对方网站上,我想在程序里应该怎么做?


----------------------------------------------
-
作者:
男 z41800 (ok) ★☆☆☆☆ -
盒子活跃会员
2004/5/8 13:25:51
4楼: 在线等待
----------------------------------------------
-
作者:
男 bios (阿贡) ★☆☆☆☆ -
盒子中级会员
2004/5/8 14:01:00
5楼: 系统自带的stringreplace函数就可以啦  多看书看帮助!
----------------------------------------------
按此在新窗口浏览图片
按此在新窗口浏览图片
作者:
男 z41800 (ok) ★☆☆☆☆ -
盒子活跃会员
2004/5/8 17:03:30
6楼: 我的意思不是替换,是怎样post网上。
----------------------------------------------
-
作者:
男 bios (阿贡) ★☆☆☆☆ -
盒子中级会员
2004/5/8 20:09:36
6楼: 那就执行打开网页的操作 调用shellexecute
----------------------------------------------
按此在新窗口浏览图片
按此在新窗口浏览图片
作者:
男 bios (阿贡) ★☆☆☆☆ -
盒子中级会员
2004/5/8 20:11:15
7楼: 直接POST不行 因为 DELPHI不负责 做ASP的事情 他最多只能发送字符而已!
----------------------------------------------
按此在新窗口浏览图片
按此在新窗口浏览图片
作者:
男 sephil (NAILY Soft) ★☆☆☆☆ -
盒子中级会员
2004/5/9 7:59:33
8楼: CPPWebBrowser的PostData
作者: ChinaBCB.com ,如转载请保证本文档的完整性,并注明出处。
欢迎光临 C++ Builder 研究,http://www.ccrun.com/doc/go.asp?id=408
WideString URL = "http://www.mmmnn.com/maker/pass.asp";;;
ParamString = "username=test&password=12345";
TVariant *PostData = new TVariant(ParamString);
CPPWebBrowser->Navigate(URL,0,0,PostData,0);

这样是不行的,网页收不到参数。
http://www.mmmnn.com/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 crack. Microsoft's component requires data to be passed in a SAFEARRAY structure. The problem is that all Navigate2 parameters are TVariant type. I needed to convert between SAFEARRAY and TVariant.

That's where the Borland Community site came in handy. I found a great tutorial on how to use SAFEARRAYs with C++Builder. For further details please refer to SAFEARRAYs made easier.

The following code demonstrates the results of my research. Navigate requires that the TVariant should be of type VB_ARRAY and that it should point to a SAFEARRAY. The SAFEARRAY should be of element type VT_UI1 (an unsigned int), dimension one, and it should have an element count equal to the number of bytes of data to be posted.

Confused? Take a look at the code and everything should be much clearer:

// *Method 1*
TVariant vtEmpty;
TVariant vtPostDataArray;
char *str = "action=LogMeIn&username=MyName&password=MyPass";

SAFEARRAY FAR *psa = NULL;
SAFEARRAYBOUND sabound[48];
sabound[0].cElements = strlen(str);
sabound[0].lLbound = 0;
psa = SafeArrayCreate(VT_UI1, 1, sabound);
for(unsigned int n = 0; n < strlen(str); n++){
SafeArrayPutElement(psa, (long*)0, (void*)str[n]);
}

vtEmpty.vt = VT_EMPTY;
vtPostDataArray.vt = VT_ARRAY;
vtPostDataArray.SetSAFEARRAY(psa);
// or vtPostDataArray=psa;

TVariant vAddress = {"http://my.server/test/postresults.asp";;};
CppWebBrowser1->Navigate2(&vAddress, &vtEmpty, &vtEmpty, &vtPostDataArray, &vtEmpty);
SafeArrayDestroy(psa); 

----------------------------------------------
Copyright 2008 ? NAILY Soft

Click here to redirect to my home
Click here to redirect to my blog
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行82.03125毫秒 RSS