Post a form to the server. Note that this will normally result in a HTTP response. This response must be processed in the same way (ie values are extracted from lines in the HTTP header).
| Return Type | Function name | Arguments |
|---|---|---|
| hzEcode | hzHttpClient::PostForm | (HttpRC&,hzUrl&,hzVect<hzString>&,hzList<hzPair>&,) |
Declared in file: hzHttpClient.h
Defined in file : hzHttpClient.cpp
Function Logic:
Function body:
hzEcode hzHttpClient::PostForm (HttpRC& hRet)hzUrl& url, hzVect<hzString>& hdrs, hzList<hzPair>& formData,
{
// Post a form to the server. Note that this will normally result in a HTTP response. This response must be processed in the same
// way (ie values are extracted from lines in the HTTP header).
//
// 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 form was posted and the response was recieved without error
_hzfunc("hzHttpClient::PostForm") ;
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
hzUrl dest ; // Url may change due to redirection
hzString dom ; // Domain part of URL
hzString res ; // Resource part of URL
hzString etag ; // Temp string for reading form data
hzEcode rc ; // Return code
// Considered a top-level function so we clear the error chain
m_Error.Clear() ;
m_Error.Printf("POSTING FORM %s\n", *url) ;
// 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) ;
P.value.UrlEncode() ;
F << P.value ;
}
dest = url ;
rc = _postform(hRet, dest, hdrs, F) ;
if (rc != E_OK)
{
m_Error.Printf("FAILED (error=%s)\n", Err2Txt(rc)) ;
return rc ;
}
for (; hRet == HTTPMSG_REDIRECT_PERM || hRet == HTTPMSG_REDIRECT_TEMP ;)
{
if (!m_Redirect)
m_Error.Printf("Oops - no URL to redirect to\n") ;
else
{
if (m_Redirect[0]== CHAR_FWSLASH)
{ dom = dest.Domain() ; dest.SetValue(dom, m_Redirect) ; }
else
dest = m_Redirect ;
m_Error.Printf("redirecting to %s\n", *dest) ;
etag = (char*) 0;
rc = _getpage(hRet, dest, etag) ;
if (rc != E_OK)
{
m_Error.Printf("Redirect FAILED (error=%s)\n", Err2Txt(rc)) ;
break ;
}
}
}
return rc ;
}