bool CWebView::LoadURL ( const SString& strURL, bool bFilterEnabled, const SString& strPostData, bool bURLEncoded ) { if ( !m_pWebView ) return false; CefURLParts urlParts; if ( !CefParseURL ( strURL, urlParts ) ) return false; // Invalid URL // Are we allowed to browse this website? if ( bFilterEnabled && g_pCore->GetWebCore ()->GetURLState ( UTF16ToMbUTF8 ( urlParts.host.str ), true ) != eURLState::WEBPAGE_ALLOWED ) return false; // Load it! auto pFrame = m_pWebView->GetMainFrame (); if ( strPostData.empty () ) { pFrame->LoadURL ( strURL ); } else { // Load URL first, see https://bitbucket.org/chromiumembedded/cef/issue/579 pFrame->LoadURL ( "about:blank" ); // Perform HTTP POST auto request = CefRequest::Create (); auto postData = CefPostData::Create (); auto postDataElement = CefPostDataElement::Create (); postDataElement->SetToBytes ( strPostData.size (), strPostData.c_str () ); postData->AddElement ( postDataElement ); if ( bURLEncoded ) { CefRequest::HeaderMap headerMap; headerMap.insert ( std::make_pair ( "Content-Type", "application/x-www-form-urlencoded" ) ); headerMap.insert ( std::make_pair ( "Content-Length", std::to_string ( strPostData.size () ) ) ); //headerMap.insert ( std::make_pair ( "Connection", "close" ) ); request->SetHeaderMap ( headerMap ); } request->SetURL ( strURL ); request->SetMethod ( "POST" ); request->SetPostData ( postData ); pFrame->LoadRequest ( request ); } return true; }
int WebTask::Request( char *url, char *post ) { // HTTPリクエスト発行 // ( url:リクエストするURL ) // ( post:NULLの場合はGET、文字列の場合はPOSTで渡す ) // if ( mode != CZHTTP_MODE_READY ) { return -1; } if ( post == NULL ) { SetVarRequestGet( url ); } else { SetPostData( post ); SetVarRequestPost( url, postdata ); } return 0; }