Discussion:
CHttpConnection/CHttpFile
(too old to reply)
a***@yahoo.ca
2005-08-24 02:30:41 UTC
Permalink
I don’t have enough information to figure out how to use WinInet to
get off the ground with an integration server. Probably I just don’t
know enough to understand the documentation I’ve been given. I tried
the following code. By the end of the routine, strBuffer is "ERROR:
Invalid Command". No idea where I'm going wrong, but a few questions
include:

1. The integration server is located at
stage.binxfer.fujifilmesys.com/FileReceiveServer.aspx. Did I pass this
to GetHttpConnection correctly?

2. The FujiFilm docs say "Parameters may be sent to the server using
the query string, the HTTP header, or from the post." Did I choose the
right verb, or does it look like the "init" request should use
HTTP_VERB_GET?

3. The commands recognized by the server include the “init”
command which is used to initialize an upload. Upon successful
completion of this command, a valid BatchID and AlbumID are returned to
the client.
􀂃Request Type: init
􀂃Required Parameters: AppKey, UserID, AlbumCreateFlag
􀂃Optional Parameters: UserName, UserPassword
􀂃Return Parameters: BatchID, AlbumID, UserID, RedirectURL

So, is there any chance that I put together the right command in
strFormData?

4. The documentation wasn’t specific about a Content-Type. Do I get
to chose, or does this suggest that the documentation was incomplete?

5. I get back “ERROR: Invalid Command.” Did this string come back
from the fujifilm server? I get the same message if I plug in the
location of the integration server into Internet Explorer.

Thanks in advance,

- Ashok Thirumurthi

try
{
// uses the MFC WinInet classes to simulate a Form POST request:
CInternetSession session;

CHttpConnection* pConnection = session.GetHttpConnection( _T
("stage.binxfer.fujifilmesys.com/FileReceiveServer.aspx") );
if ( pConnection && m_pPrintService )
{
CHttpFile* pFile = pConnection->OpenRequest
(CHttpConnection::HTTP_VERB_POST);
if ( pFile )
{
CString strHeaders = _T ("Content-Type:
application/index-www-form-urlencoded");

CNkvResource strRes;
std::string str;
strRes.LoadString( NKVMAKERESOURCEID( NKID_APPKEY ), &str);

std::string sUserName;
m_pPrintService->GetUserName (sUserName);

std::string sPassword;
m_pPrintService->GetPassword (sPassword);

// URL-encoded form variables -
CString strFormData;
strFormData.Format ( _T
("RequestType=init&AppKey=%s&UserID=+UserName=%s&UserPassword=%s&AlbumCreateFlag=createalways"),

str.c_str (), sUserName.c_str (), sPassword.c_str () );

if ( pFile->SendRequest (strHeaders, (LPVOID)(LPCTSTR)strFormData,
strFormData.GetLength ()) == TRUE )
{
DWORD dwReturn;
pFile->QueryInfoStatusCode (dwReturn);

if ( dwReturn == HTTP_STATUS_OK )
{
char szBuffer [1024];
UINT nRead = pFile->Read (szBuffer, 1023);

CString strBuffer = szBuffer;
if ( strBuffer.Find ("ERROR") >= 0 )
{
// strBuffer is "ERROR: Invalid Command"
}
}
}
delete pFile;
pFile = 0;
}
delete pConnection; // TODO: Persist the session and connection
until the files are uploaded
pConnection = 0;
}
}
catch ( CInternetException * e )
{
if ( e )
{
e->ReportError ();
}
}
a***@yahoo.ca
2005-08-24 19:11:27 UTC
Permalink
For reference, here is the packet dump of a successfull
authentication.....


POST /FileReceiveServer.aspx HTTP/1.0
AlbumCreateFlag: createalways
AppKey: D463-7272-ED59-DEA1
RequestType: init
UserName: ***@yahoo.com
UserPassword: fran
Content-Type: text/plain; charset="us-ascii"
User-Agent: My Ritz Uploader
Content-Length: 2






HTTP/1.1 200 OK
Connection: close
Date: Wed, 24 Aug 2005 18:12:34 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 1.1.4322
Result: SUCCESS
BatchID: 11038
AlbumID: 1948
UserID: 125279
RedirectURL: http://newstage.ritzpix.com/traffic_controller.asp
Set-Cookie: ASP.NET_SessionId=m5lcj255mzipihehjeenq145; path=/
Cache-Control: private
Content-Type: text/html; charset=utf-8
Content-Length: 118


Result=SUCCESS&BatchID=11038&AlbumID=1948&UserID=125279&RedirectURL=http://newstage.ritzpix.com/traffic_controller.asp
a***@yahoo.ca
2005-08-26 15:04:51 UTC
Permalink
I noticed that GetLastError returns 122 (ERROR_INSUFFICIENT_BUFFER)
after the call to OpenRequest. Does this suggest a problem, or can
this error be ignored?

- Ashok
a***@yahoo.ca
2005-08-26 16:46:40 UTC
Permalink
I got it working using explicit calls to AddRequestHeaders for each of
the request parameters,

- Ashok

Loading...