1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| public static ManualResetEvent allDone = new ManualResetEvent(false);
public void Run()
{
//Création du cookie Container... no pb ici
// Create a new HttpWebRequest object.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.CookieContainer = cc;
// Set the ContentType property.
// Set the Method property to 'POST' to post data to the URI.
request.Method = "POST";
// Start the asynchronous operation.
request.BeginGetRequestStream(new AsyncCallback(ReadCallback), request);
// Keep the main thread from continuing while the asynchronous
// operation completes. A real world application
// could do something useful such as updating its user interface.
allDone.WaitOne();
// Get the response.
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream streamResponse = response.GetResponseStream();
StreamReader streamRead = new StreamReader(streamResponse);
string responseString = streamRead.ReadToEnd();
Form f = new Form();
f.Text = "Browser";
f.Width = 900;
f.Height = 500;
WebBrowser wbb = new WebBrowser();
wbb.DocumentText = responseString;
wbb.Document.Encoding = "ISO-8859-1";
wbb.Dock = DockStyle.Fill;
f.Controls.Add(wbb);
f.ShowDialog();
// Close the stream object.
streamResponse.Close();
streamRead.Close();
// Release the HttpWebResponse.
response.Close();
}
private static void ReadCallback(IAsyncResult asynchronousResult)
{
HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
// End the operation.
Stream postStream = request.EndGetRequestStream(asynchronousResult);
string postData = "mode=newtopic&subject=post00&message=baaah&f=4"; //je voudrais envoyer ces données mais il me dit : mode du sujet non spécifié alors que la valeur du mode est bonne...
// Convert the string into a byte array.
byte[] byteArray = Encoding.ASCII.GetBytes(postData);
// Write to the request stream.
postStream.Write(byteArray, 0, postData.Length);
postStream.Close();
allDone.Set();
} |
Partager