Whatever you want here. Just make sure it's off topic. Which...I guess if the topic is being off topic, then it means you should be on topic. Understand?
-
3cmSailorfuku
- Posts: 354
- Joined: Mon Jan 21, 2008 6:25 pm
#1
Post
by 3cmSailorfuku » Tue Feb 26, 2008 10:44 am
If anyone's familiar with C#;
Code: Select all
public class PostUtility
{
public static string HttpPost(string uri, string parameters)
{
WebRequest webRequest = WebRequest.Create(uri);
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.Headers.Add("Cookie: xxxxx");
webRequest.Method = "POST";
byte[] bytes = Encoding.ASCII.GetBytes(parameters);
Stream os = null;
try
{
webRequest.ContentLength = bytes.Length;
os = webRequest.GetRequestStream();
os.Write(bytes, 0, bytes.Length);
}
finally
{
if (os != null)
{
os.Close();
}
}
return null;
}
}
It does work, however after 2 times Sending the Post Header the tool will freeze, which I cannot explain to myself. I've tried opening the stream already just on pressing start and closing it later, but that didn't helped either.
The original is from
http://en.csharp-online.net/HTTP_Post
And theres no offtopic forum
-
Administrator
- Site Admin
- Posts: 5307
- Joined: Sat Jan 05, 2008 4:21 pm
#2
Post
by Administrator » Tue Feb 26, 2008 11:27 am
There is now
If you run this locally, and have it dump to a file rather than to your standard output stream, what is produced(if anything)?
I'll have somebody that knows C# look at this later (assuming I remember). He's sleeping at the moment.
-
3cmSailorfuku
- Posts: 354
- Joined: Mon Jan 21, 2008 6:25 pm
#3
Post
by 3cmSailorfuku » Tue Feb 26, 2008 11:43 am
Silly me, forgot to delete the content of the stream x,x
Code: Select all
try
{ // get the response
WebResponse webResponse = webRequest.GetResponse();
if (webResponse == null)
{ return null; }
StreamReader sr = new StreamReader (webResponse.GetResponseStream());
return sr.ReadToEnd ().Trim ();
}
Appending that solved it. And the code above is a bitch. Literally. I forgot that a class is using new memory on use.
Who is online
Users browsing this forum: No registered users and 1 guest