1.11M Members

Need code

 
0
 

I need a sample code to retrieve the source code of a page .

Ex : I have www.blahblahblah.tld/file.ext?id=blah

I want to retrieve in a char the source code of that site.

Thanks

 
0
 

Learn socket programming. How to do that will depend on the operating system you are using. If *nix you need POSIX sockets. MS-Windows use WinSocket.

 
1
 

Using what OS?
On windows, you can use C++/CLI and open a WebClient^ to a page.

 
0
 

It can be also easily done with C# and VB. But since this is c++ forum ...

 
0
 

First thank you all for your reply.
And i am using Windows ...

I know in C# is more easy but i need C++.

Ill try the method with sockets and ... Thines, can you give me an example of WebClient^ ?
Thanks.

EDIT : My project is a Windows Form type.

This can be done more easly with the webBrowser1 from Tools ?

 
0
 

>>EDIT : My project is a Windows Form type.

That is not c++ -- its CLI/C++ which is slightly different language

>>This can be done more easly with the webBrowser1 from Tools ?

Probably.

 
0
 

First thank you all for your reply.
EDIT : My project is a Windows Form type./QUOTE]

What are you going to DO with the contents of the web page when you get it?

 
0
 

In final i found how to take the contents of the page like that :

private: System::Void webBrowser1_Navigated(System::Object^  sender, System::Windows::Forms::WebBrowserNavigatedEventArgs^  e) {
             if( this->webBrowser1->DocumentText->ToString() != "err" )
             {

                 // here i need something like that :
                                // this->webBrowser1->DocumentText->ToString() is
                                 // blahtext|blahtext2|blahtext3
                                 // i want to break that string into 3 another like :

                                 this->webBrowser1->DocumentText->ToString() 
                                     to
                                 blahtext
                                 blahtext2
                                 blahtext3

                                 this->label6->Text = Variablethatcontains blahtext
 this->label7->Text = Variablethatcontains blahtext2
this->label8->Text = Variablethatcontains blahtext3

             }
         }
 
1
 

I'm still confused.
Can you just use this->webBrowser1->DocumentText->ToString()->Split( /*parameters go here*/) ?
to convert that text into an array?

I still need to ask, are you just attempting to get some text from a page or do you actually need to start a browser object?

 
0
 

Anyway i made it but ....
I need to retrieve data from a server and that solution with read web page isn't good ...
I need MYSQL.
How to implement mysql with C++ ?
I don't think is an default include ...

 
1
 

If you have not already downloaded the connector (for .net), you will need to get it:
http://www.mysql.com/downloads/connector/net/

Once you get that installed, you can add a reference to the MySql.Data DLL entry and add "using namespace MySql:: Data::MySqlClient;" to the code that will use it.

 
0
 

And if i build my application, and i publish it .. i need to put the mysql dll near it ?

Ex APP.exe
mydll.exe

If yes, is possible to embed dll in app ? I want One file for my app.

 
0
 

Later Reply : How to use that Mysql Connector ? Exists any tutorial or don't know im very 'newb' at C++ and MYSQL .............

 
2
 

Have you tried this?

 
0
 

Yes i tried but when i try to compile im getting a nasty error :

Cannot find : boost/system.hpe
Don't know exactly the error ( i closed visual studio ).

LE : LotOfLaugh : When i reopened visual studio and added again the connector the error dissapeared.

As i seen on Google ....
The examples are like that :

/* MySQL Connector/C++ specific headers */
#include <driver.h>
#include <connection.h>
#include <statement.h>
#include <prepared_statement.h>
#include <resultset.h>
#include <metadata.h>
#include <resultset_metadata.h>
#include <exception.h>
#include <warning.h>

But i don't have that... I have.. using namespace MySql:: Data::MySqlClient;

 
0
 

Don't include those headers.


There is documentation on the site.

...but here is a code snippet assuming you have a database table named "SOME_TABLE" that has a column called "NAME":

#include "stdafx.h"

using namespace System;
using namespace System::Collections::Generic;
using namespace System::IO;//assuming you still need this for the other part
using namespace System::Net; //assuming you still need this for the other part
using namespace MySql::Data::MySqlClient;

bool GetListFromDb(List<String^>^ lst_strNames, String^% strError)
{
   bool blnRetVal = true;

   try
   {
      MySqlConnectionStringBuilder^ csb = gcnew MySqlConnectionStringBuilder();
      csb->Server = "{server address goes here}";
      csb->Database = "{database name goes here}";
      csb->UserID = "{user id goes here}";
      csb->Password = "{password goes here}";

      MySqlConnection^ conn = gcnew MySqlConnection(csb->ToString());
      String^ strSQL = "SELECT NAME from SOME_TABLE";
      MySqlDataReader^ rdr = (gcnew MySqlCommand(strSQL, conn))->ExecuteReader();
      while(rdr->Read())
      {
         lst_strNames->Add(rdr["NAME"]->ToString()->Trim());
      }
      rdr->Close();
      conn->Close();
   }
   catch(Exception^ exc)
   {
      blnRetVal = false;
      strError = exc->Message;
   }

   return blnRetVal;
}

...and it can be called like this:

String^ strError = "";
    List<String^>^ lst_strNames = gcnew List<String^>();

    if(!GetListFromDb(lst_strNames, strError))
    {
       System::Diagnostics::Debug::WriteLine("Could not load list: " + strError);
       return -1;
    }
 
0
 

Tried

String^ strError = "";
    List<String^>^ lst_strNames = gcnew List<String^>();

			 MySqlConnectionStringBuilder^ csb = gcnew MySqlConnectionStringBuilder();
      csb->Server = "localhost";
      csb->Database = "dumi";
      csb->UserID = "dumi";
      csb->Password = "dumi";
 
      MySqlConnection^ conn = gcnew MySqlConnection(csb->ToString());
      String^ strSQL = "SELECT * from servers";
      MySqlDataReader^ rdr = (gcnew MySqlCommand(strSQL, conn))->ExecuteReader();
      while(rdr->Read())
      {
         lst_strNames->Add(rdr["id"]->ToString()->Trim());
      }
      rdr->Close();
      conn->Close();

Getting

1>c:\users\adrian\desktop\dhlds2\dhlds2\Form1.h(668): error C2065: 'List' : undeclared identifier
1>c:\users\adrian\desktop\dhlds2\dhlds2\Form1.h(668): error C2275: 'System::String' : illegal use of this type as an expression
1>          c:\program files\reference assemblies\microsoft\framework\.netframework\v4.0\mscorlib.dll : see declaration of 'System::String'
1>c:\users\adrian\desktop\dhlds2\dhlds2\Form1.h(668): error C2059: syntax error : '>'
1>c:\users\adrian\desktop\dhlds2\dhlds2\Form1.h(681): error C2065: 'lst_strNames' : undeclared identifier
1>c:\users\adrian\desktop\dhlds2\dhlds2\Form1.h(681): error C2227: left of '->Add' must point to class/struct/union/generic type
 
1
 

Check my edit (as I added the namespaces):

 
0
 

Now is working thank you soo much !

Two last things :

String^ strError = "";
List<String^>^ lst_strNames = gcnew List<String^>();

if(!GetListFromDb(lst_strNames, strError))
{
this->textBox4->Text = lst_strNames; // how to do that ?
}

And the 2nd ... that connector needs an .dll or something present near the application ? If yes ... how to 'hide it' inside the application ?

 
0
 

What you're asking is how to convert a list of Strings to a single String.

I would do it like this:

using namespace System::Linq;

...

this->textBox4->Text = 
       String::Join("\n",
         Enumerable::ToArray<String^>(lst_strNames));
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article