Écriture dans un fichier distant

ricklekebekoi Messages postés 303 Date d'inscription mardi 11 février 2003 Statut Membre Dernière intervention 24 avril 2009 - 19 mai 2008 à 17:38
sachie Messages postés 93 Date d'inscription jeudi 7 juin 2007 Statut Membre Dernière intervention 16 septembre 2010 - 4 sept. 2008 à 11:03
Allo !
Je tente d'écrire sur un fichier distant auquel j'ai tous les droits. Ensuite, j'execute un script PHP qui se sert de ce fichier et dont la réponse ne m'importe pas :)

C'était selon moi un truc hyper simple, mais visiblement les ressources sur l'écriture a distance semblent minces.

Voila mon code, qui plante en me disant que STREAMWRITER ne peut pas prendre en parametre un fichier distant.

string title = textBox1.Text;
string msg = textBox2.Text;
StreamWriter sw = new StreamWriter( "http://www.url.com/postTemp.txt" );
sw.WriteLine( "{TITLE}{0}{ENDTITLE}",title );
sw.WriteLine( "{0}", msg );
sw.Close();
string endpoint = "http://www.url.com/postMessage.php";
int forum = 49;
string requestURL = String.Format( "{0}?forum={1}", endpoint, forum );
HttpWebRequest rq = (HttpWebRequest)WebRequest.Create( requestURL );
rq.GetResponse();

Comment je bypass le bobo ? merci !


Eric

2 réponses

ricklekebekoi Messages postés 303 Date d'inscription mardi 11 février 2003 Statut Membre Dernière intervention 24 avril 2009 5
19 mai 2008 à 17:40
Ouais visiblement OPERA bug avec la textbox :)

Mon message formaté:


Allo !
Je tente d'écrire sur un fichier distant auquel j'ai tous les droits.
Ensuite, j'execute un script PHP qui se sert de ce fichier et dont la réponse ne m'importe pas :)
C'était selon moi un truc hyper simple, mais visiblement les ressources sur l'écriture a distance semblent minces.
Voila mon code, qui plante en me disant que STREAMWRITER ne peut pas prendre en parametre un fichier distant.

string title = textBox1.Text;
string msg = textBox2.Text;
StreamWriter sw = new StreamWriter( "http://www.url.com/postTemp.txt" );
sw.WriteLine( "{TITLE}{0}{ENDTITLE}",title );
sw.WriteLine( "{0}", msg );
sw.Close();
string endpoint = "http://www.url.com/postMessage.php";
int forum = 49;
string requestURL = String.Format( "{0}?forum={1}", endpoint, forum );
HttpWebRequest rq = (HttpWebRequest)WebRequest.Create( requestURL );
rq.GetResponse();

Comment je bypass le bobo ? merci !



Eric
0
sachie Messages postés 93 Date d'inscription jeudi 7 juin 2007 Statut Membre Dernière intervention 16 septembre 2010 2
4 sept. 2008 à 11:03
essaye ça:

WebClient client = new WebClient();
StreamWriter sw = new StreamWriter(client.OpenWrite("http://www.url.com/postTemp.txt") );
0
Rejoignez-nous