• 6370阅读
  • 2回复

QHttp 访问 webservice【已解决】 [复制链接]

上一主题 下一主题
离线banyibanyi
 

只看楼主 倒序阅读 楼主  发表于: 2010-03-17
— 本帖被 XChinux 从 General Qt Programming 移动到本区(2011-01-02) —
在论坛上找了一下 虽然有 但是还是不怎么能看懂
假如我要登陆一个网站,得到网站的源码

下载我知道周末弄,但是如何post看不太明白  尤其是在setHeader里 不知道都是什么

应用版主以前的代码
QString data("name=你好中国&id=1234567890&addr=asdfghjkl");

    http->setHost("localhost");

    QHttpRequestHeader header("POST", "/biselaw/vote.php") ;  这里的路径是什么路径?
    header.setValue("Host", "localhost") ;
    header.setContentType("application/x-www-form-urlencoded");
    http->request(header, data.toUtf8()) ;
这样就可以吗?有明白的朋友能不能帮我整理下整个过程 谢谢 十分感谢
[ 此帖被banyibanyi在2010-03-30 08:39重新编辑 ]
离线banyibanyi

只看该作者 1楼 发表于: 2010-03-17
我看见网上有这样写的

QUrl *url=new QUrl(”https://www.google.com/accounts/ClientLogin”);
QString* date = new QString(”bianhao=010202004090100011″);


QByteArray postData = “\nservice=reader&”;
postData += “Email=”;
postData += QUrl::toPercentEncoding(”asdfasdf@gmail.com” );
postData += “&Passwd=”;
postData += QUrl::toPercentEncoding(”asdfasdfsadf” );

QHttpRequestHeader header(”POST”, url->path());
header.setContentType(”application/x-www-form-urlencoded”);
QByteArray  searchString(”complete=1&hl=zh-CN&lr=lang_zh-CN%7Clang_zh-TW&newwindow=1&q=qhttp&start=10&sa=N”);
header.setContentLength(searchString.length());
http->setHost(url->host(),QHttp::ConnectionModeHttps);
f.setFileName(”results.html”);
f.open(QIODevice::WriteOnly | QIODevice::Truncate);
mHttpReqId= http->request(header,postData,&f);

不知道这里的postData是什么意思  还有searchString是什么意思 希望能解释一下
离线banyibanyi

只看该作者 2楼 发表于: 2010-03-17
问题已经解决 只要吧header信息设置全 还有postDate复合服务器要求就行了
快速回复
限100 字节
 
上一个 下一个