By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,985 Members | 1,776 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,985 IT Pros & Developers. It's quick & easy.

Get content from web file

P: n/a
Hello Programmers,

I try to get my application to work but i have a question!

How can i get content from a file from http.

Eg.
http://test.com/text.txt <-- in this file i have for example a city
name "Copenhagen" this text would i like to get in my c++ application.

Are there some professionals, who can help me with this?

Best Regards
Thusan - Denmark

Aug 14 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On Aug 14, 4:45 pm, m...@thusan.com wrote:
Hello Programmers,

I try to get my application to work but i have a question!

How can i get content from a file from http.

Eg.http://test.com/text.txt<-- in this file i have for example a city
name "Copenhagen" this text would i like to get in my c++ application.

Are there some professionals, who can help me with this?

Best Regards
Thusan - Denmark
it's a OS's specific question. C++ does not have anything to deal with
http.
For example, for windows there is a header wininet.h that might help.

Aug 14 '07 #2

P: n/a
r
m...@thusan.com wrote:
Hello Programmers,

I try to get my application to work but i have a question!

How can i get content from a file from http.
Use a library like libcurl. Or if you are writing an application with
a GUI toolkit, the toolkit may already have something for handling
HTTP.

Aug 14 '07 #3

P: n/a
It's a application to Windows CE, Have you any code example to how i
can fix this?

This is the code i have now:

// ExampleManualDlg.cpp : implementation file
//
#include <iostream>
#include <sstream>
#include <fstream>
#include "stdafx.h"
#include "ExampleManual.h"
#include "ExampleManualDlg.h"

#include "sdkconstants.h"
#include "TomTomAPI.h"
#include "TomTomGoFileLayer.h"
#include <stdio.h>
#include <string>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#define CLIENT_NAME "client"

int res;
CString str;
CString strout;
CTomTomAPI::TError err;
CTomTomAPI::TVersion version;
CTomTomAPI::TGeocodeResult GeoRes;
char *aCity;
char *aStreet;
char *aNumber;
char *aPostCode;

void CExampleManualDlg::OnButtontt()
{

MTomTomCommunicationLayerInterface *comms =
DEFAULT_TRANSPORTATION_LAYER(CLIENT_NAME,
2005,TOMTOM_TCPIP_PORT);
CTomTomAPI api(*comms);

//Read

aCity = "Randers";
aStreet = "Urtevangen";
aNumber = "9";
aPostCode = "8900";

res =
api.NavigateToAddress(&err,&*aCity,&*aStreet,&*aNu mber,&*aPostCode);
res = api.BringNavigatorToForeground(&err);

strout = "";
str.Format(_T("Geocode = %d\r\n"), res);
strout = strout + aStreet + " | " + aNumber + " | " + aPostCode +
" | " + aCity;
m_EditResult.SetWindowText(strout);

delete comms;

}

Aug 15 '07 #4

P: n/a
Hi!

ma**@thusan.com schrieb:
It's a application to Windows CE, Have you any code example to how i
can fix this?

This is the code i have now:

// ExampleManualDlg.cpp : implementation file
[snip]
#include <stdio.h>
prefer <cstdio>
#include <string>

#ifdef _DEBUG
#define new DEBUG_NEW
Don't define keywords to mean something different. Don't "#define new ...".
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#define CLIENT_NAME "client"
Why not use a char array here, too? Does the macro further down require
CLIENT_NAME to be a macro?

static char CLIENT_NAME[] = "client";
int res;
CString str;
CString strout;
CTomTomAPI::TError err;
CTomTomAPI::TVersion version;
CTomTomAPI::TGeocodeResult GeoRes;
char *aCity;
char *aStreet;
char *aNumber;
char *aPostCode;
I guess these are not global variables, but members of CExampleManualDlg.
void CExampleManualDlg::OnButtontt()
{

MTomTomCommunicationLayerInterface *comms =
DEFAULT_TRANSPORTATION_LAYER(CLIENT_NAME,
2005,TOMTOM_TCPIP_PORT);
Further down you "delete comms;" which means it is dynamically
allocated. So prefer automatic memory management:

const std::auto_ptr<MTomTomCommunicationLayerInterface>
comms = DEFAULT_TRANSPORTATION_LAYER(CLIENT_NAME,
2005,TOMTOM_TCPIP_PORT);

You will probably need #include <memoryfor auto_ptr.
CTomTomAPI api(*comms);

//Read

aCity = "Randers";
aStreet = "Urtevangen";
aNumber = "9";
aPostCode = "8900";
Notice: string literals contain chars and must not be modified. you
therefore try to declare the variables as "const char *aCity;". But
maybe the "NavigateToAddress" functions does not permit this.
>
res =
api.NavigateToAddress(&err,&*aCity,&*aStreet,&*aNu mber,&*aPostCode);
"&*aCity" is the same as "aCity". Just drop the "&*" part everywhere:
api.NavigateToAddress(&err, aCity, aStreet, aNumber, aPostCode);
res = api.BringNavigatorToForeground(&err);

strout = "";
str.Format(_T("Geocode = %d\r\n"), res);
strout = strout + aStreet + " | " + aNumber + " | " + aPostCode +
" | " + aCity;
m_EditResult.SetWindowText(strout);

delete comms;
When using auto_ptr just drop the "delete comms;". It will be
automatically deleted.

HTH,
Frank
Aug 15 '07 #5

P: n/a
Hi!

I forgot to mention:

ma**@thusan.com schrieb:
strout = "";
str.Format(_T("Geocode = %d\r\n"), res);
strout = strout + aStreet + " | " + aNumber + " | " + aPostCode +
" | " + aCity;
m_EditResult.SetWindowText(strout);
Maybe stringstreams are easier for this:

std::ostringstream stream;
stream
//should not need '\r', but try:
<< "Geocode = " << res << '\n'
<< aStreet << " | "
<< aNumber << " | "
<< aPostCode << " | "
<< aCity
;
m_EditResult.SetWindowText(stream.str().c_str());
you need #include <sstreamand <ostreamfor this.

Frank
Aug 15 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.