Third party/EasySoap++-0.6.1/src/SOAPonHTTP.cpp
// send the payload.  can only be called ONCE per
// payload. 
//
send the payload.  can only be called ONCE per
payload.
send the payload . can only be called ONCE per payload .
size_t
SOAPonHTTP::Write(const SOAPMethod& method, const char *payload, size_t payloadsize)
{
	int retry = 5;
	int ret = 0;
	while (retry--)
	{
		m_http.BeginPost(m_endpoint.Path());
		m_http.WriteHeader("User-Agent", m_userAgent.IsEmpty() ?
				DEFAULT_USERAGENT : (const char *)m_userAgent);
		m_http.WriteHeader("Content-Type", "text/xml; charset=\"UTF-8\"");
		if (!m_endpoint.User().IsEmpty() || !m_endpoint.Password().IsEmpty())
		{
			SOAPString up = m_endpoint.User();
			up.Append(":");
			up.Append(m_endpoint.Password());
			SOAPString enc;
			SOAPBase64Base::Encode(up, up.Length(), enc);
			up = "Basic ";
			up.Append(enc);
			m_http.WriteHeader("Authorization", (const char *)up);
		}
		m_http.Write("SOAPAction:");
		if (method.GetSoapAction())
		{
			m_http.Write(" \"");
			m_http.Write(method.GetSoapAction());
			m_http.Write("\"");
		}
		m_http.WriteLine();
		ret = m_http.PostData(payload, payloadsize);
		 If resource moved (temporarily or permanently)
		if (ret == 301 || ret == 302)
		{
			const char *location = m_http.GetHeader("Location");
			if (!location)
				throw SOAPException("HTTP code %d did not return a Location header.", ret);
			SOAPUrl newendpoint = location;
			 If only the path changed, we don't
			 need to re-connect.
			if (newendpoint.Hostname() != m_endpoint.Hostname() ||
				newendpoint.Port() != m_endpoint.Port())
				m_http.ConnectTo(newendpoint);
			m_endpoint = newendpoint;
		}
		else
			break;
	}
	 Only valid return codes  we know of.  200 is success,
	 500 could be a soap fault.
	if (ret != 200 && ret != 500)
		throw SOAPException("Unexpected return code: %s",
			(const char *)m_http.GetRequestMessage());
	bool isxml = true;
	const char *contype = m_http.GetHeader("Content-Type");
	if (contype)
		isxml = (sp_strstr(contype, "text/xml") != 0);
	if (!isxml)
		throw SOAPException("Unexpected return Content-Type: %s", contype);
	return ret;
}
size_t SOAPonHTTP :: Write ( const SOAPMethod & method , const char * payload , size_t payloadsize ) { int retry = 5 ; int ret = 0 ; while ( retry -- ) { m_http . BeginPost ( m_endpoint . Path ( ) ) ; m_http . WriteHeader ( " " , m_userAgent . IsEmpty ( ) ? DEFAULT_USERAGENT : ( const char * ) m_userAgent ) ; m_http . WriteHeader ( " " , " \" \" " ) ; if ( ! m_endpoint . User ( ) . IsEmpty ( ) || ! m_endpoint . Password ( ) . IsEmpty ( ) ) { SOAPString up = m_endpoint . User ( ) ; up . Append ( " " ) ; up . Append ( m_endpoint . Password ( ) ) ; SOAPString enc ; SOAPBase64Base :: Encode ( up , up . Length ( ) , enc ) ; up = " " ; up . Append ( enc ) ; m_http . WriteHeader ( " " , ( const char * ) up ) ; } m_http . Write ( " " ) ; if ( method . GetSoapAction ( ) ) { m_http . Write ( " \" " ) ; m_http . Write ( method . GetSoapAction ( ) ) ; m_http . Write ( " \" " ) ; } m_http . WriteLine ( ) ; ret = m_http . PostData ( payload , payloadsize ) ; if ( ret == 301 || ret == 302 ) { const char * location = m_http . GetHeader ( " " ) ; if ( ! location ) throw SOAPException ( " " , ret ) ; SOAPUrl newendpoint = location ; if ( newendpoint . Hostname ( ) != m_endpoint . Hostname ( ) || newendpoint . Port ( ) != m_endpoint . Port ( ) ) m_http . ConnectTo ( newendpoint ) ; m_endpoint = newendpoint ; } else break ; } if ( ret != 200 && ret != 500 ) throw SOAPException ( " " , ( const char * ) m_http . GetRequestMessage ( ) ) ; bool isxml = true ; const char * contype = m_http . GetHeader ( " " ) ; if ( contype ) isxml = ( sp_strstr ( contype , " " ) != 0 ) ; if ( ! isxml ) throw SOAPException ( " " , contype ) ; return ret ; }
send the payload.
send the payload .
// // If resource moved (temporarily or permanently) // If only the path changed, we don't // need to re-connect. // Only valid return codes  we know of.  200 is success, // 500 could be a soap fault.