Fog Creek Software
Discussion Board




Question about using scoutSubmit.asp

I will admit that I am not extremely experienced in using calls to asp files up front.  I am trying to use Microsoft's Wininet.dll internet functions by creating a post and then passing our error information for the autosubmitted errors to scoutSubmit.asp from within a C++ application(using CHttpFile's Send Request).  I would like to format my new task in the fashion that the example task is shown on the FogBugz page "Using FogBUGZ to Get Crash Reports From Users - Automatically! " with each piece of information showing up on a separate line in the task.  However when I add my error text to the &Extra parameter,  the string always seems to have the newlines removed in the resultant task.  Is there some special formatting that I need to use to allow my tasks to be formatted with extra info across multiple lines like in the example task?

Bryan Wilcox
Monday, April 26, 2004

its probably because of chr(10) and chr(13)
(carriage return AND line feed)
just include both \r\n

also, you should just use bugzscout.dll.  It has an activex object which already does what you are doing.  (its just a tiny little http post object).

Michael H. Pryor
Fog Creek Software
Monday, April 26, 2004

Is there some documentation on how to use the DLL?  I had a few problems with the ActiveX part of the example.  I couldn't get the ScoutSample.exe to work on my machine and I would like to use the DLL in a MS VC++ environment, not VB like the ScoutSample.vbp.  I actually am not having any problems communicating with the scoutSubmit.asp, other than the issue with the \n's and a problem with some extraneous &nbsp's being added to my output messages when they are from the ASP page.

Bryan Wilcox
Monday, April 26, 2004

I'm also having problems using ScoutSubmit.asp from a C++ program. I decided to use WinInet instead of the ActiveX control, because it seemed like the lesser of two evils.

I can't seem to format the request properly. I get an XML error response "User not valid: ", despite trying to use FriendlyResponse for plain-text.

Some sample code for WinInet or the MFC WinInet wrappers would be great.

John Van vliet
Tuesday, April 27, 2004

I finally got the basics working using the MFC WinInet wrappers. Here's a code snippet that may be useful:

=====
CInternetSession *pSess  = NULL;
CHttpConnection  *pConn  = NULL;
CHttpFile        *pFile  = NULL;
    
TRY
{
    pSess = new CInternetSession();
    pConn = pSess->GetHttpConnection(pszServerURL);
    pFile = pConn->OpenRequest(CHttpConnection::HTTP_VERB_POST,
                            _T("/fogbugz/scoutsubmit.asp"),
                      NULL, 1, NULL, NULL,
                      INTERNET_FLAG_RELOAD);

    CString sForm;
    _addFormField(sForm, _T("FriendlyResponse"),    _T("1"));
    _addFormField(sForm, _T("ScoutUserName"),      _T("<User Name>"));
    _addFormField(sForm, _T("ScoutProject"),        _T("<Project Name>"));
    _addFormField(sForm, _T("ScoutArea"),          _T("<Project Area>"));
    _addFormField(sForm, _T("ScoutDefaultMessage"), _T("<Default Message>"));
    _addFormField(sForm, _T("ForceNewBug"),        _T("0"));
    _addFormField(sForm, _T("Description"),        _T("<Error Title>"));
    _addFormField(sForm, _T("Extra"),              _T("<Error Body>"));
    _addFormField(sForm, _T("Email"),              _T("<User Email>"));

    pFile->AddRequestHeaders("Content-Type: application/x-www-form-urlencoded\n");
    BOOL bSend = pFile->SendRequest(NULL, NULL, (LPVOID)(LPCTSTR)sForm, sForm.GetLength());

    DWORD dwCode;
    pFile->QueryInfoStatusCode(dwCode);
    if (dwCode == 200)
    {
        CString sResponse;
        pFile->ReadString(sResponse);
        // TODO: Process the response
    }
}
CATCH(CInternetException, pEx)
{
    // TODO: Exception handling
}
END_CATCH
=====

John Van vliet
Tuesday, April 27, 2004

I forgot the utility functions:

=====
void _addFormField(CString &rsForm, const _TCHAR *szName, const _TCHAR *szValue)
{
    if (rsForm.GetLength() > 0) rsForm.Append("&");
    rsForm.AppendFormat("%s=%s", szName, _URLEncode(szValue));
}
=====

See http://www.codeproject.com/string/urlencode.asp for an implementation of the URLEncode() function.

John Van vliet
Tuesday, April 27, 2004

It's me again with a couple of things...

1. Bryan Wilcox pointed out the InternetCanonicalizeUrl() function in WinInet. It's a better alternative than my URLEncode() method if you're developing in Windows.

2. The new line problem when using WinInet can be solved with a simple search-and-replace before calling InternetCanonicalizeUrl():

sExtra.Replace("\n", "%0D%0A");  // sExtra is a MFC CString

Note that replacing "\n" with "\r\n" does not seem to work. The "\r\n" character sequence seems to be converted into a
&nbsp by FogBugz.

John Van vliet
Tuesday, April 27, 2004

*  Recent Topics

*  Fog Creek Home