00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <e32test.h>
00025 #include <f32file.h>
00026 #include <http/mhttpauthenticationcallback.h>
00027
00028
00029
00030 const TInt KMaxContentTypeSize = 64;
00031
00032
00033
00034
00035
00036 class CHttpEventHandler;
00037 class CHttpExampleUtils;
00038
00039
00048 class CHttpClient : public CBase, public MHTTPDataSupplier,
00049 public MHTTPAuthenticationCallback
00050 {
00051 public:
00052 virtual ~CHttpClient();
00053 static CHttpClient* NewLC();
00054 static CHttpClient* NewL();
00055 void StartClientL();
00056
00057 virtual TBool GetNextDataPart(TPtrC8& aDataPart);
00058 virtual void ReleaseData();
00059 virtual TInt OverallDataSize();
00060 virtual TInt Reset();
00061
00062
00063 virtual TBool GetCredentialsL(const TUriC8& aURI, RString aRealm,
00064 RStringF aAuthenticationType,
00065 RString& aUsername,
00066 RString& aPassword);
00067
00068 protected:
00069 CHttpClient();
00070 void ConstructL();
00071 private:
00072
00073 enum TMenuItems
00074 {
00075 EGet,
00076 EPost,
00077 EHead,
00078 ETrace,
00079 EToggleVerbosity,
00080 EQuit
00081 };
00082
00083 void ResetTimeElapsed();
00084 void DisplayTimeElapsed();
00085
00086 void InvokeHttpMethodL(const TDesC8& aUri, RStringF aMethod);
00087 void SetHeaderL(RHTTPHeaders aHeaders, TInt aHdrField, const TDesC8& aHdrValue);
00088 void GetRequestBodyL(RStringF& aMethod);
00089 void GetPostBodyManuallyL();
00090
00091 private:
00092 TTime iLastTimeStamp;
00093 TInt iDataChunkCount;
00094 RHTTPSession iSess;
00095 RHTTPTransaction iTrans;
00096 TBool iHasARequestBody;
00097 RFs iFileServ;
00098 RFile iReqBodyFile;
00099 TFileName iReqBodyFileName;
00100 TParse iParsedFileName;
00101 TBuf<KMaxContentTypeSize> iReqBodyContentType;
00102 CHttpEventHandler* iTransObs;
00103 HBufC8* iReqBodySubmitBuffer;
00104 TPtr8 iReqBodySubmitBufferPtr;
00105 CHTTPFormEncoder* iFormEncoder;
00106 TBool iManualPost;
00107 CHttpExampleUtils* iUtils;
00108 };
00109
00110
00111
00114 class CHttpEventHandler : public CBase, public MHTTPTransactionCallback
00115 {
00116 public:
00117 virtual ~CHttpEventHandler();
00118 static CHttpEventHandler* NewLC(CHttpExampleUtils& aUtils);
00119 static CHttpEventHandler* NewL(CHttpExampleUtils& aUtils);
00120 void SetVerbose(TBool aVerbose);
00121 TBool Verbose() const;
00122
00123
00124
00125 virtual void MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent);
00126 virtual TInt MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& aEvent);
00127
00128 protected:
00129 CHttpEventHandler(CHttpExampleUtils& aUtils);
00130 void ConstructL();
00131 private:
00132 void DumpRespHeadersL(RHTTPTransaction& aTrans);
00133 void DumpRespBody(RHTTPTransaction& aTrans);
00134 void DumpIt(const TDesC8& aData);
00135 TBool iVerbose;
00136 TBool iSavingResponseBody;
00137 RFs iFileServ;
00138 RFile iRespBodyFile;
00139 TFileName iRespBodyFileName;
00140 TParse iParsedFileName;
00141 MHTTPDataSupplier* iRespBody;
00142 CHttpExampleUtils& iUtils;
00143 };
00144