symbian 使用http get post方式获取网页信息
2010-05-31 19:38:00 来源:WEB开发网核心提示:void CClientEngine::IssueHTTPGetL(const TDesC8& aUri)//以get方式获取一个网页 { SetupConnectionL(); // Parse string to URI (as defined in RFC2396) TUriParser8 uri; uri.Pa
void CClientEngine::IssueHTTPGetL(const TDesC8& aUri)//以get方式获取一个网页 {
SetupConnectionL(); // Parse string to URI (as defined in RFC2396) TUriParser8
uri; uri.Parse(aUri);//把传入的uri转化为标准格式 // Get request method string for HTTP GET
RStringF method = iSession.StringPool().StringF(HTTP::EGET,
RHTTPSession::GetTable());//设置以get的方法读取 // Open transaction with previous method
and parsed uri. This class will // receive transaction events in MHFRunL and
MHFRunError. iTransaction = iSession.OpenTransactionL(uri, *this,
method);//打开一个连接 使用设置好的方法和指定的uri // Set headers for request; user agent and
accepted content type RHTTPHeaders hdr =
iTransaction.Request().GetHeaderCollection();//设置一个http头 SetHeaderL(hdr,
HTTP::EUserAgent, KUserAgent); SetHeaderL(hdr, HTTP::EAccept, KAccept); //
Submit the transaction. After this the framework will give transaction // events
via MHFRunL and MHFRunError. iTransaction.SubmitL();//调用 MHFRunL iRunning =
ETrue; _LIT(KConnecting,"Connecting..."); iObserver.ClientEvent(KConnecting); }
// ----------------------------------------------------------------------------
// CClientEngine::IssueHTTPPostL() // // Start a new HTTP POST transaction. //
----------------------------------------------------------------------------
void CClientEngine::IssueHTTPPostL(const TDesC8& aUri, const TDesC8&
aContentType, const TDesC8& aBody) { SetupConnectionL(); // Parse string to
URI TUriParser8 uri; uri.Parse(aUri); // Copy data to be posted into member
variable; iPostData is used later in // methods inherited from
MHTTPDataSupplier. delete iPostData; iPostData =
aBody.AllocL();//把取得的数据放到iPostData里 // Get request method string for HTTP POST
RStringF method = iSession.StringPool().StringF(HTTP::EPOST,//设置post方法
RHTTPSession::GetTable()); // Open transaction with previous method and parsed
uri. This class will // receive transaction events in MHFRunL and MHFRunError.
更多精彩
赞助商链接