ablazso
asked on
Is there a better way to create a long URL parameter in C++?
Are there better ways than multiple strcpy-s and strconcat-s to assemble a long parameter? This long parameter is needed by the web service (it is a strange WSDL less service) I need to use.
Here is an excerpt from my program:
using namespace MSXML2; // For Msxml3.dll.
using namespace std;
.
.
.
HRESULT hr = CoInitialize(NULL);
IXMLHTTPRequestPtr pXMLHTTPReq = NULL;
_bstr_t test = "user=Fah8tdCFWZrQ&passwor d=tv3WKK5f 4vnfWZPp&v ersion=3.1 &test_requ est=True&d elim=True& delim_char =|&relay=F alse&first _name=Alex &last_name =Gincola&a ddress=101 Main&city=Phonenix&state=A Z&zip=6052 5&amount=1 00¤c y=USD&meth od=CHECK&t ype=AUTH&a ba=1220006 61&bank_ac ct_num=062 4100154&ba nk_acct_ty pe=CHECKIN G&bank_nam e=Bank Of America&acct_name=Alex Blazso&trx_type=WEB";
try {
IServerXMLHTTPRequestPtr pXMLHTTPReq = NULL;
hr = pXMLHTTPReq.CreateInstance (__uuidof( ServerXMLH TTP30));
hr = pXMLHTTPReq->open("POST", "https://secure.aaaa/bbbb/cccc.dll", VARIANT_TRUE);
hr = pXMLHTTPReq->setRequestHea der("Conte nt-Type", "applications/x-www-form-u rlencoded" );
hr = pXMLHTTPReq->send(test);
long readyState = READYSTATE_UNINITIALIZED;
MSG msg;
while (readyState != READYSTATE_COMPLETE) {
if (PeekMessage(&msg, 0, 0 ,0, PM_REMOVE)) {
TranslateMessage (&msg);
DispatchMessage (&msg);
}
readyState = pXMLHTTPReq->GetreadyState ();
}
MessageBox(NULL, "readyState is COMPLETE ", "readystate", MB_OK);
_bstr_t tempStr = pXMLHTTPReq->responseText;
const char* lpstr = (LPCSTR)tempStr;
MessageBox(NULL, lpstr, "readystate", MB_OK);
int inLen = strlen(lpstr);
printf ("\nrespData=[%s] len=[%d]", lpstr, inLen);
long status= pXMLHTTPReq->Getstatus();
.
.
.
Here is an excerpt from my program:
using namespace MSXML2; // For Msxml3.dll.
using namespace std;
.
.
.
HRESULT hr = CoInitialize(NULL);
IXMLHTTPRequestPtr pXMLHTTPReq = NULL;
_bstr_t test = "user=Fah8tdCFWZrQ&passwor
try {
IServerXMLHTTPRequestPtr pXMLHTTPReq = NULL;
hr = pXMLHTTPReq.CreateInstance
hr = pXMLHTTPReq->open("POST", "https://secure.aaaa/bbbb/cccc.dll", VARIANT_TRUE);
hr = pXMLHTTPReq->setRequestHea
hr = pXMLHTTPReq->send(test);
long readyState = READYSTATE_UNINITIALIZED;
MSG msg;
while (readyState != READYSTATE_COMPLETE) {
if (PeekMessage(&msg, 0, 0 ,0, PM_REMOVE)) {
TranslateMessage (&msg);
DispatchMessage (&msg);
}
readyState = pXMLHTTPReq->GetreadyState
}
MessageBox(NULL, "readyState is COMPLETE ", "readystate", MB_OK);
_bstr_t tempStr = pXMLHTTPReq->responseText;
const char* lpstr = (LPCSTR)tempStr;
MessageBox(NULL, lpstr, "readystate", MB_OK);
int inLen = strlen(lpstr);
printf ("\nrespData=[%s] len=[%d]", lpstr, inLen);
long status= pXMLHTTPReq->Getstatus();
.
.
.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
alternatively, use stringstream. That allows to concatenate different types as in sprintf but is safe. You can concatenate any type that has a overload of of operator<<.
#include <sstream>
#include <string>
using namespace std;
ostringstream oss;
oss << "That is a long string that contains the number " << 12345 << " and text.":
// you can get the concatenated string by
const char* psz = oss.str().c_str();
Regards, Alex
#include <sstream>
#include <string>
using namespace std;
ostringstream oss;
oss << "That is a long string that contains the number " << 12345 << " and text.":
// you can get the concatenated string by
const char* psz = oss.str().c_str();
Regards, Alex
http://www.cplusplus.com/ref/cstdio/sprintf.html