求救关于Http post的实现

bestdelpher 2008-05-10 02:37:41
怎样实现一个在第2版和第三版上可用的Http post架构,我现在的想法是要实现一个请求WebService服务的功能,将XML数据直接POST到服务器,,请提供援助。。
...全文
457 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 bestdelpher 的回复:]
我在网上找到了Chttp类(参见http://www.cppblog.com/Khan/archive/2007/12/19/39024.html,注意库文件中有个ecom.h的引用,要改为ecom/ecom.h),经测试,在SDK 3rd fp1上可以运行,但是在SDK 2 FP3上,提示要安装什么网络插件,有大虾弄过没有?
[/Quote]


嘿嘿, 居然翻到我blog上去了..... 貌似我在3.1和2.3都测试过.... 真机是n95 和 n70 都没有问题. 也没有提示要什么网络插件啊...奇怪了啊
bestdelpher 2008-05-17
  • 打赏
  • 举报
回复
???????????????????
yillchen 2008-05-14
  • 打赏
  • 举报
回复
楼上的,请不要误会,CHttpEngine是我自己包的,你也可以起任何名字
bestdelpher 2008-05-14
  • 打赏
  • 举报
回复
在SDK 3rd fp1上可以运行,但是在SDK 2 FP3上,提示要安装什么网络插件,有大虾弄过没有?
bestdelpher 2008-05-14
  • 打赏
  • 举报
回复
是CHttpEngine类哈
bestdelpher 2008-05-14
  • 打赏
  • 举报
回复
我在网上找到了Chttp类(参见http://www.cppblog.com/Khan/archive/2007/12/19/39024.html,注意库文件中有个ecom.h的引用,要改为ecom/ecom.h),经测试,在SDK 3rd fp1上可以运行,但是在SDK 2 FP3上,提示要安装什么网络插件,有大虾弄过没有?
bestdelpher 2008-05-14
  • 打赏
  • 举报
回复
不是指得你那个,我是指http://www.cppblog.com/Khan/archive/2007/12/19/39024.html上的内容,人家也正好用到了这个类名
yillchen 2008-05-13
  • 打赏
  • 举报
回复
楼上的,不要意思,由于程序是公司的,不方便给你
3rd的SDK是要用SISX安装的,他需要认证,该程序需要用到一些特定的CAPABILITY,如NetworkServices,具体你看看HELP
miyunhong 2008-05-12
  • 打赏
  • 举报
回复

楼上的,,谢谢你的回复,,

我把我的SIS文件传给你试下好吗,,,或者把你的传给我在机上试下,,我现在用下面地址代码生成了SIS,,但在手机上打开时报系统错误,,执行不了,,

http://www.forum.nokia.com/info/sw.nokia.com/id/6ae1a078-1545-4c2c-b98f-68366474aa6d/S60_Platform_HTTP_Client_API_Example_v2_1_en.zip.html

代码和你上面的类似,,

我搞了一个星期了,,找了很多资料都不行,,,很多都是手机上不行,,模拟器又可以,,

644621379@qq.com


yillchen 2008-05-12
  • 打赏
  • 举报
回复
// ----------------------------------------------------------------------------
// CHTTPEngine::IssueHTTPGetL()
//
// Start a new HTTP GET transaction.
// ----------------------------------------------------------------------------
void CHTTPEngine::IssueHTTPGetL(const TDesC8& aUri)
{
SetupConnectionL();

// Parse string to URI (as defined in RFC2396)
TUriParser8 uri;
uri.Parse(aUri);

// Get request method string for HTTP GET
RStringF method = iSession.StringPool().StringF(HTTP::EGET,
RHTTPSession::GetTable());

// Open transaction with previous method and parsed uri. This class will
// receive transaction events in MHFRunL and MHFRunError.
iTransaction = iSession.OpenTransactionL(uri, *this, method);

// Set headers for request; user agent and accepted content type
RHTTPHeaders hdr = iTransaction.Request().GetHeaderCollection();
SetHeaderL(hdr, HTTP::EUserAgent, KUserAgent);
SetHeaderL(hdr, HTTP::EAccept, KAccept);

// Submit the transaction. After this the framework will give transaction
// events via MHFRunL and MHFRunError.
iTransaction.SubmitL();

iRunning = ETrue;
_LIT(KConnecting,"Connecting...");
iObserver.ClientEvent(KConnecting);
}
// ----------------------------------------------------------------------------
// CHTTPEngine::SetupConnectionL()
//
// The method set the internet access point and connection setups.
// ----------------------------------------------------------------------------
void CHTTPEngine::SetupConnectionL()
{
if( iConnectionSetupDone )
return;

iConnectionSetupDone = ETrue;

//open socket server and start the connection
User::LeaveIfError(iSocketServ.Connect());
User::LeaveIfError(iConnection.Open(iSocketServ));

// open the IAP communications database
CCommsDatabase* commDB = CCommsDatabase::NewL(EDatabaseTypeIAP);
CleanupStack::PushL(commDB);

// initialize a view
CCommsDbConnectionPrefTableView* commDBView =
commDB->OpenConnectionPrefTableInRankOrderLC(ECommDbConnectionDirectionUnknown);

// go to the first record
User::LeaveIfError(commDBView->GotoFirstRecord());

// Declare a prefTableView Object.
CCommsDbConnectionPrefTableView::TCommDbIapConnectionPref pref;

// read the connection preferences
commDBView->ReadConnectionPreferenceL(pref);
TUint32 iapID = pref.iBearer.iIapId;

// pop and destroy the IAP View
CleanupStack::PopAndDestroy(commDBView);

// pop and destroy the database object
CleanupStack::PopAndDestroy(commDB);

// Now we have the iap Id. Use it to connect for the connection.
// Create a connection preference variable.
TCommDbConnPref connectPref;

// setup preferences
connectPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
connectPref.SetDirection(ECommDbConnectionDirectionUnknown);
connectPref.SetBearerSet(ECommDbBearerGPRS);
//Sets the CommDb ID of the IAP to use for this connection
connectPref.SetIapId(iapID);

User::LeaveIfError(iConnection.Start(connectPref));

//set the sessions connection info
RStringPool strPool = iSession.StringPool();
RHTTPConnectionInfo connInfo = iSession.ConnectionInfo();

//to use our socket server and connection
connInfo.SetPropertyL ( strPool.StringF(HTTP::EHttpSocketServ,
RHTTPSession::GetTable() ), THTTPHdrVal (iSocketServ.Handle()) );

connInfo.SetPropertyL ( strPool.StringF(HTTP::EHttpSocketConnection,
RHTTPSession::GetTable() ),
THTTPHdrVal (REINTERPRET_CAST(TInt, &(iConnection))) );
}
这是我使用的代码,在N81的手机上测试是可以的,你可以参考参考
我是使用3RD + CARBIDE
我的手机网络选择的CMNET的连网方式,用CMWAP可能不行,你看看你 的手机连网方式是什么
miyunhong 2008-05-12
  • 打赏
  • 举报
回复

我只需要Get,,
1、2、3楼的代码我都试了,,

在Nokia 6110 Naviagation 真机上都没成功(都没有出现选择接入点界面,,执行根本反应),,但模拟器上没有问题,yunsi ,,,

开发环境是,,,VS2003 + sdk 3rd fp1;


Eddy_0825 2008-05-11
  • 打赏
  • 举报
回复
可以参考一下blog:http://blog.csdn.net/Eddy_0825/archive/2007/05/10/1603270.aspx#794800
yanro 2008-05-11
  • 打赏
  • 举报
回复
/**
*
* @brief Definition of CHTTPExampleEngine
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*/

// INCLUDE FILES

// Class include
#include "HTTPExampleEngine.h"

// System includes
#include <chttpformencoder.h> // CHTTPFormEncoder
#include <httpstringconstants.h> // HTTP string table
#include <rhttpheaders.h> // RHTTPHeaders

// User includes
#include "HTTPExample.hrh" // EMaxNameLength

// CONSTANTS
// HTTP header values
_LIT8(KUserAgent, "HTTPExample (1.0)"); // Name of this client app
_LIT8(KAccept, "text/*"); // Accept any (but only) text content
_LIT8(KPostParamName, "NAME"); // Name of the parameter sent in a POST request
_LIT8(KPostContentType, "text/plain"); // Content type sent in a POST request

// URL for POST request.
//_LIT8(KPostUri, "http://cgi.www.emccsoft.com/cgi-bin/www.emccsoft.com/post.pl");
_LIT8(KPostUri, "http://www.magpiemobile.com/cgi-bin/book_post.cgi");


// ================= MEMBER FUNCTIONS =======================

/**
* 2-phase constructor
*
* @param aObserver An observer of this engine (e.g. the UI)
*/
CHTTPExampleEngine* CHTTPExampleEngine::NewL(MHTTPExampleEngineObserver& aObserver)
{
CHTTPExampleEngine* self = new (ELeave) CHTTPExampleEngine(aObserver);
CleanupStack::PushL(self);
self->ConstructL();
CleanupStack::Pop(self);
return self;
}

/**
* C++ constructor
*
* @param aObserver An observer of this engine (e.g. the UI)
*/
CHTTPExampleEngine::CHTTPExampleEngine(MHTTPExampleEngineObserver& aObserver)
: iObserver(aObserver)
{
}

/**
* 2nd-phase constructor
*/
void CHTTPExampleEngine::ConstructL()
{
// Open the RHTTPSession
iSession.OpenL();

// Construct the form encoder
iFormEncoder = CHTTPFormEncoder::NewL();
}

/**
* C++ destructor
*/
CHTTPExampleEngine::~CHTTPExampleEngine()
{
// Close session
iSession.Close(); // Will also close any open transactions
delete iResponseBuffer;
delete iFormEncoder;
delete iUri;
}

/**
* Override of pure virtual method in MHTTPTransactionCallback.
* Called to report progress by a currently outstanding transaction.
*
* @param aTransaction The transaction reporting progress
* @param aEvent The event being notified
*/
void CHTTPExampleEngine::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent)
{
switch (aEvent.iStatus)
{
case THTTPEvent::EGotResponseHeaders:
{
// HTTP response headers have been received.
// Pass status information to observer.
RHTTPResponse resp = aTransaction.Response();

// Get status code
TInt statusCode = resp.StatusCode();

// Get status text
RStringF statusStr = resp.StatusText();
HBufC* statusBuf = HBufC::NewLC(statusStr.DesC().Length());
statusBuf->Des().Copy(statusStr.DesC());

// Inform observer
iObserver.ResponseStatusL(statusCode, *statusBuf);

CleanupStack::PopAndDestroy(statusBuf);
}
break;


case THTTPEvent::EGotResponseBodyData:
{
// Get text of response body
MHTTPDataSupplier* dataSupplier = aTransaction.Response().Body();
TPtrC8 ptr;
dataSupplier->GetNextDataPart(ptr);

// Convert to 16-bit descriptor
HBufC* buf = HBufC::NewLC(ptr.Length());
buf->Des().Copy(ptr);

// Append to iResponseBuffer
if (!iResponseBuffer)
{
iResponseBuffer = buf->AllocL();
}
else
{
iResponseBuffer = iResponseBuffer->ReAllocL(iResponseBuffer->Length() + buf->Length());
iResponseBuffer->Des().Append(*buf);
}

// Release buf
CleanupStack::PopAndDestroy(buf);

// Release the body data
dataSupplier->ReleaseData();
}
break;

case THTTPEvent::EResponseComplete:
{
// Pass the response buffer by reference to the observer
iObserver.ResponseReceivedL(*iResponseBuffer);
}
break;
}
}

/**
*/
TInt CHTTPExampleEngine::MHFRunError(TInt aError, RHTTPTransaction /*aTransaction*/, const THTTPEvent& /*aEvent*/)
{
return aError;
}


/**
* Initiate a GET request
*
* @param aUri The URI to get
*/
void CHTTPExampleEngine::GetRequestL(const TDesC& aUri)
{
// Parse the URI
ParseUriL(aUri);

// Create the transaction
iTransaction = iSession.OpenTransactionL(iUriParser, *this,
iSession.StringPool().StringF(HTTP::EGET, RHTTPSession::GetTable()));

// Set transaction headers
RHTTPHeaders headers = iTransaction.Request().GetHeaderCollection();
AddHeaderL(headers, HTTP::EUserAgent, KUserAgent);
AddHeaderL(headers, HTTP::EAccept, KAccept);

// Submit the request
iTransaction.SubmitL();
}


/**
* Initiate a POST request
*
* @param aName The user's name
*/
void CHTTPExampleEngine::PostRequestL(const TDesC& aName)
{
// Build form encoder
// Start by removing any previous content
delete iFormEncoder;
iFormEncoder = NULL;
iFormEncoder = CHTTPFormEncoder::NewL();
TBuf8<EMaxNameLength> buf8;
buf8.Copy(aName);
iFormEncoder->AddFieldL(KPostParamName, buf8);

// Create transaction
iUriParser.Parse(KPostUri);
iTransaction = iSession.OpenTransactionL(iUriParser, *this,
iSession.StringPool().StringF(HTTP::EPOST, RHTTPSession::GetTable()));

// Set transaction headers
RHTTPHeaders headers = iTransaction.Request().GetHeaderCollection();
AddHeaderL(headers, HTTP::EUserAgent, KUserAgent);
AddHeaderL(headers, HTTP::EAccept, KAccept);
AddHeaderL(headers, HTTP::EContentType, KPostContentType);

// Set the form encoder as the data supplier
iTransaction.Request().SetBody(*iFormEncoder);

// Submit the request
iTransaction.SubmitL();
}


//
// Utility methods
//

/**
* Parse a URI
*
* @param aUri The URI to be parsed
*/
void CHTTPExampleEngine::ParseUriL(const TDesC& aUri)
{
// Convert the URI to an 8-bit descriptor
// then set iUriParser to point at it
delete iUri;
iUri = NULL;
iUri = HBufC8::NewL(aUri.Length());
iUri->Des().Copy(aUri);
User::LeaveIfError(iUriParser.Parse(*iUri));
}


/**
* Add a header to a header set
*
* @param aHeaders The header set to be modified
* @param aHeaderField The name of the header to be added
* @param aHeaderValue The value for the header to be added
*/
void CHTTPExampleEngine::AddHeaderL(RHTTPHeaders aHeaders, TInt aHeaderField, const TDesC8& aHeaderValue)
{
RStringPool stringPool = iSession.StringPool();
RStringF valStr = stringPool.OpenFStringL(aHeaderValue);
THTTPHdrVal headerVal(valStr);
aHeaders.SetFieldL(stringPool.StringF(aHeaderField, RHTTPSession::GetTable()), headerVal);
valStr.Close();
}


/**
* Cancel any outstanding transaction
*/
void CHTTPExampleEngine::Cancel()
{
iTransaction.Cancel();
}
Atoric 2008-05-11
  • 打赏
  • 举报
回复
楼主你好:
1、你有《Series 60应用程序开发》这本书么?
有的话,在书的第十章(Post具体是在375页)又讲这个的;
2、有一个HTTP客户端的示例代码:
http://www.forum.nokia.com/info/sw.nokia.com/id/6ae1a078-1545-4c2c-b98f-68366474aa6d/S60_Platform_HTTP_Client_API_Example_v2_1_en.zip.html
你可以参考一下;

不好意思的说,我就用过Get,Post我没有用过,希望上面的东西能对你有用。

3,119

社区成员

发帖
与我相关
我的任务
社区描述
塞班系统(Symbian系统)是塞班公司为手机而设计的操作系统,它的前身是英国宝意昂公司的 EP ( Electronic Piece of cheese)操作系统。
社区管理员
  • Symbian社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧