📄 orcoperhttp.cpp
字号:
/* Copyright (c) 2007, Nokia. All rights reserved */
#include <aknnotewrappers.h>
#include <f32file.h>
#include "OrcerAppUi.h"
#include "ORCOperHttp.h"
#include "Orcer.hrh"
#include "Orcer.rsg"
_LIT(KStatusFormat, "%d: %S"); // Format string for status returned from web server, e.g. "200: OK" or "404: Not Found"
const TInt KStatusCodeLength = 100; // Enough room in a descriptor for code + ": "
CORCOperHttp* CORCOperHttp::NewL()
{
CORCOperHttp* self = NewLC();
CleanupStack::Pop(self);
return self;
}
CORCOperHttp* CORCOperHttp::NewLC()
{
CORCOperHttp* self = new (ELeave) CORCOperHttp();
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
void CORCOperHttp::ConstructL()
{
m_pTime = CTimeOutTimer::NewL(0,*this);
}
CORCOperHttp::CORCOperHttp()
{
m_pHttpEngine = CHTTPEngine::NewL(*this);
}
CORCOperHttp::~CORCOperHttp()
{
MEMORY_FREE(m_psRturnText);
MEMORY_FREE(m_pHttpEngine);
MEMORY_FREE(m_pTime);
}
void CORCOperHttp::SendUrl(const TDesC& aType, const TDesC& aName,const TDesC& aPsw)
{
_LIT(KHead,"http://www.ldci.mobi/snsProject/");
_LIT(KSynbol,"?");
_LIT(KPhon,"mobile=");
_LIT(KPsw,"&pass=");
TBuf<10> sType(aType);
TBuf<EMaxUrlLength> iUrl;
if (sType.Compare(_L("update")) != 0)
{
iUrl.Copy(KHead);
iUrl.Append(aType);
iUrl.Append(KSynbol);
iUrl.Append(KPhon);
iUrl.Append(aName);
iUrl.Append(KPsw);
iUrl.Append(aPsw);
}
if (m_pTime->IsActive()) m_pTime->Cancel();
m_pTime->After(15*1000*1000);
m_pHttpEngine->GetRequestL(iUrl);
}
TInt CORCOperHttp::GetResponse()
{
return m_iType;
}
void CORCOperHttp::ParseResponse(const TDesC& aResponse)
{
m_psRturnText = HBufC::NewL(aResponse.Length()+1);
m_psRturnText->Des().Copy(aResponse);
TBuf<10> label2;
label2.Append(_L("<type>"));
TBuf<10> label3;
label3.Append(_L("</type>"));
TBuf<10> label4;
label4.Append(_L("<result>"));
TBuf<10> label5;
label5.Append(_L("</result>"));
TBuf<10> sRss;
sRss.Copy(m_psRturnText->Des().Mid(0,5));
sType.Copy(m_psRturnText->Mid(m_psRturnText->Find(label2)+label2.Length(),
m_psRturnText->Find(label3) - m_psRturnText->Find(label2)-label2.Length()));
sResult.Copy(m_psRturnText->Mid(m_psRturnText->Find(label4)+label4.Length(),
m_psRturnText->Find(label5) - m_psRturnText->Find(label4)-label4.Length()));
if (0 == sType.Compare(_L("regi")))
{
m_pLoginView->SetResponseType(sType,sResult);
}
else if (0 == sType.Compare(_L("update")))
{
m_pFunView->SetResponseType(sResult);
m_pOperBook->SetSelUpResult(sResult);
}
else if (0 == sType.Compare(_L("login")))
{
m_pLoginView->SetResponseType(sType,sResult);
}
else
m_pOperBook->ResPonseContent(aResponse);
// }
}
void CORCOperHttp::ResponseReceivedL(const TDesC& aResponseBuffer)
{
HBufC* buf = HBufC::NewLC(aResponseBuffer.Length() + KStatusCodeLength);
buf->Des().Format(KStatusFormat, 200, &aResponseBuffer);//
CAknInformationNote* note = new (ELeave) CAknInformationNote;
note->ExecuteLD(*buf);
// ParseText(aStatusText);
CleanupStack::PopAndDestroy(buf);
// Pass the response buffer by reference to the observer
this->ParseResponse(aResponseBuffer);
}
void CORCOperHttp::ResponseStatusL(TInt aStatusCode, const TDesC& aStatusText)
{
// HBufC* buf = HBufC::NewLC(aStatusText.Length() + KStatusCodeLength);
// buf->Des().Format(KStatusFormat, aStatusCode, &aStatusText);//
// CAknInformationNote* note = new (ELeave) CAknInformationNote;
// note->ExecuteLD(*buf);
//// ParseText(aStatusText);
// CleanupStack::PopAndDestroy(buf);
}
void CORCOperHttp::DoSentBodyPost(const TDesC& aBody)
{
m_pHttpEngine->PostRequestL(aBody);
}
void CORCOperHttp::TimerExpired()
{
if (m_pTime->IsActive()) m_pTime->Cancel();
// out of service
TBuf<20> sBuf;
CEikonEnv::Static()->ReadResource(sBuf,R_ORCER_LOGIN_CONTENTFAIL);
CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
informationNote->ExecuteLD(sBuf);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -