void CSendGetUrlReqSocket::OnConnect(int nErrorCode) { if (0 != nErrorCode) { if (thePrefs.GetVerbose()) { CString strUrlPath(GetUrlPath()); CString strServer(GetServer()); strUrlPath.Replace(_T("%"), _T("%%")); AddDebugLogLine(false, _T("将要取%s,但连接%s返回失败。"), strUrlPath, strServer); } return; } CStringA strHttpRequest; strHttpRequest.AppendFormat("%s %s HTTP/1.0\r\n", m_bIsPost ? "POST" : "GET", GetUrlPath()); strHttpRequest.AppendFormat("Host: %s\r\n", GetServer()); strHttpRequest.AppendFormat("Accept: */*\r\n"); if(m_bIsPost) { strHttpRequest.AppendFormat("Accept-Encoding: none\r\n"); strHttpRequest.AppendFormat("Content-Type: application/x-www-form-urlencoded\r\n"); strHttpRequest.AppendFormat("Content-Length: %d\r\n", m_strPost.GetLength()); } //strHttpRequest.AppendFormat("Connection: Keep-Alive\r\n"); strHttpRequest.Append("\r\n"); if(m_bIsPost) { strHttpRequest.Append(m_strPost); } if (thePrefs.GetVerbose()) { CString strRequest(strHttpRequest); strRequest.Replace(_T("%"), _T("%%")); AddDebugLogLine(false, _T("与服务器 %s 连接成功,准备发送:"), CString(GetServer())); AddDebugLogLine(false, strRequest); } CRawPacket* pHttpPacket = new CRawPacket(strHttpRequest); SendPacket(pHttpPacket); SetHttpState(HttpStateRecvExpected); }
bool CSendGetUrlReqSocket::SendRequest(void) { CStringA strUrlPath = GetUrlPath(); if (strUrlPath.IsEmpty()) return false; if (!Create()) return false; Connect(GetServer(), GetPort()); return true; }
void CSendGetUrlReqSocket::DataReceived(const BYTE* pucData, UINT uSize) { if (thePrefs.GetVerbose()) { CString strUrlPath(GetUrlPath()); strUrlPath.Replace(_T("%"), _T("%%")); CStringA straRecv((char *)pucData, uSize); AddDebugLogLine(false, _T("取%s时,返回结果:"), strUrlPath); AddDebugLogLine(false, CString(straRecv)); } CHttpClientReqSocket::DataReceived(pucData, uSize); }
void CSendGetUrlReqSocket::OnConnect(int nErrorCode) { if (0 != nErrorCode) { if (thePrefs.GetVerbose()) { CString strUrlPath(GetUrlPath()); CString strServer(GetServer()); strUrlPath.Replace(_T("%"), _T("%%")); AddDebugLogLine(false, _T("将要取%s,但连接%s返回失败。"), strUrlPath, strServer); } return; } CStringA strHttpRequest; strHttpRequest.AppendFormat("GET %s HTTP/1.0\r\n", GetUrlPath()); strHttpRequest.AppendFormat("Host: %s\r\n", GetServer()); strHttpRequest.AppendFormat("Accept: */*\r\n"); //strHttpRequest.AppendFormat("Connection: Keep-Alive\r\n"); strHttpRequest.AppendFormat("\r\n"); if (thePrefs.GetVerbose()) { CString strRequest(strHttpRequest); strRequest.Replace(_T("%"), _T("%%")); AddDebugLogLine(false, _T("与服务器 %s 连接成功,准备发送:"), CString(GetServer())); AddDebugLogLine(false, strRequest); } CRawPacket* pHttpPacket = new CRawPacket(strHttpRequest); SendPacket(pHttpPacket); SetHttpState(HttpStateRecvExpected); }