Post a form to the server but do not seek a HTTP response.
| Return Type | Function name | Arguments |
|---|---|---|
| hzEcode | hzHttpClient::PostAjax | (HttpRC&,hzUrl&,hzVect<hzString>&,hzList<hzPair>&,) |
Declared in file: hzHttpClient.h
Defined in file : hzHttpClient.cpp
Function Logic:
Function body:
hzEcode hzHttpClient::PostAjax (HttpRC& hRet)hzUrl& url, hzVect<hzString>& hdrs, hzList<hzPair>& formData,
{
// Post a form to the server but do not seek a HTTP response.
//
// Arguments: 1) hRet HTTP return code
// 2) url The URL
// 3) hdrs Lines in HTTP header
// 4) formData The form data to be submitted
//
// Returns: E_ARGUMENT If the URL is not supplied or no domain specified
// E_NOSOCKET If the external server has closed the connection
// E_NODATA If nothing was recived
// E_FORMAT If the response was malformed
// E_OK If the AJAX request was sent and the response was recieved without error
_hzfunc("hzHttpClient::PostAjax") ;
hzList<hzPair>::Iter iD ; // Form data iterator
hzChain F ; // Form data in submissible form
hzCookie cookie ; // Cookie (drawn from supplied map of cookies)
hzPair P ; // Form data field
hzString dom ; // Domain part of URL
hzString res ; // Resource part of URL
hzString S ; // Temp string for reading form data
uint32_t nPort ; // Port (from URL)
uint32_t nIndex ; // Form data iterator
hzEcode rc ; // Return code
// Clear() ;
m_Header.Clear() ;
m_Content.Clear() ;
m_Request.Clear() ;
if (!formData.Count())
return E_NODATA ;
for (iD = formData ; iD.Valid() ; iD++)
{
P = iD.Element() ;
if (F.Size())
F.AddByte(CHAR_AMPSAND) ;
F << P.name ;
F.AddByte(CHAR_EQUAL) ;
F << P.value ;
}
dom = url.Domain() ;
res = url.Resource() ;
nPort = url.Port() ;
if (url.IsSSL())
m_Request.Printf("POST https://%s%s HTTP/1.1\r\n", *dom, *res) ;
else
m_Request.Printf("POST http://%s%s HTTP/1.1\r\n", *dom, *res) ;
// m_Request << "POST " << "http://" << dom << res << " HTTP/1.1\r\n" ;
m_Request << "Accept: text/*\r\n" ;
m_Request << "Accept-Language: en-gb\r\n" ;
// m_Request << "Accept-Encoding:\r\n" ;
// m_Request << "Accept-Encoding: gzip, deflate\r\n" ;
for (nIndex = 0; nIndex < m_Cookies.Count() ; nIndex++)
{
cookie = m_Cookies.GetObj(nIndex) ;
if (cookie.m_Flags & COOKIE_HTTPONLY)
continue ;
m_Request.Printf("Cookie: %s=%s\r\n", *cookie.m_Name, *cookie.m_Value) ;
}
// m_Request << "User-Agent: HadronZoo/0.8 (compatible; MSIE 6.0;)\r\n" ;
m_Request << "User-Agent: HadronZoo/0.8 Linux 2.6.18\r\n" ;
m_Request.Printf("Content-Length: %d\r\n", F.Size()) ;
m_Request << "Host: " << dom << "\r\n" ;
if (hdrs.Count())
{
for (nIndex = 0; nIndex < hdrs.Count() ; nIndex++)
// m_Request << hdrs.Element(nIndex) ;
m_Request << hdrs[nIndex] ;
}
m_Request << "Connection: close\r\n\r\n" ;
m_Request << F ;
S = m_Request ;
threadLog("Sending [\n%s]\n", *S) ;
// Connect to server
if (url.IsSSL())
rc = m_Webhost.ConnectSSL(dom, nPort) ;
else
rc = m_Webhost.ConnectStd(dom, nPort) ;
if (rc != E_OK)
return rc ;
// Send request
rc = m_Webhost.Send(m_Request) ;
return rc ;
}