64,654
社区成员
发帖
与我相关
我的任务
分享
void upload(const ScoringInfoV2 &info)
{
const unsigned short cusBufferSize = 4096;
char* cpTemp = new char[cusBufferSize];
// Print vehicle info
for( long i = 0; i < info.mNumVehicles; ++i )
{
VehicleScoringInfoV2 &vinfo = info.mVehicle[ i ];
sprintf(cpTemp, "%s%d,%d,%s,%s,%d,%d,%d,%d,%d,%d,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f\n"
,cpTemp,GetTickCount()/1000,i
, vinfo.mDriverName,vinfo.mVehicleName,vinfo.mIsPlayer, vinfo.mControl
, vinfo.mPlace,vinfo.mFinishStatus,vinfo.mNumPitstops,vinfo.mTotalLaps
,vinfo.mBestSector1, vinfo.mBestSector2, vinfo.mBestLapTime
,vinfo.mLastSector1, vinfo.mLastSector2, vinfo.mLastLapTime
,vinfo.mCurSector1, vinfo.mCurSector2);
}
//例如,此时cpTemp 为"aabb";
_beginthreadex(NULL,NULL, http_post,cpTemp,0,NULL);
}
unsigned int __stdcall http_post(LPVOID lpParameter)
{
CURL *curl;
CURLcode res;
struct curl_httppost *formpost=NULL;
struct curl_httppost *lastptr=NULL;
struct curl_slist *headerlist=NULL;
static const char buf[] = "Expect:";
//在xp中正常,值为"aabb"
//在win server2003 中
//此时,ttt的值就已经是"aabbaabb"
char* ttt=(char*)lpParameter;
FILE *fo = fopen( "aaaaaaa.txt", "a" );
if( fo != NULL )
{
fprintf( fo, "%s",ttt);
fclose( fo );
}
//后面是用curl上传的一些操作,可忽略
curl_global_init(CURL_GLOBAL_ALL);
/* Fill in the submit field too, even if this is rarely needed */
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "data",
CURLFORM_COPYCONTENTS, ttt,
CURLFORM_END);
curl = curl_easy_init();
/* initalize custom header list (stating that Expect: 100-continue is not
wanted */
headerlist = curl_slist_append(headerlist, buf);
if(curl)
{
/* what URL that receives this POST */
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
res = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
/* then cleanup the formpost chain */
curl_formfree(formpost);
/* free slist */
curl_slist_free_all (headerlist);
}
return 0;
}