EMO Style ForumPro - Hos Geldiniz
Giriş yap

Şifremi unuttum

Istatistikler
Toplam 203 kayıtlı kullanıcımız var
Son kaydolan kullanıcımız: posta59

Kullanıcılarımız toplam 1186 mesaj attılar bunda 862 konu
Tarıyıcı
 Kapı
 Indeks
 Üye Listesi
 Profil
 SSS
 Arama
Arama
 
 

Sonuç :
 


Rechercher çıkıntı araştırma

RSS akısı


Yahoo! 
MSN 
AOL 
Netvibes 
Bloglines 


Kimler hatta?
Toplam 5 kullanıcı online :: 0 Kayıtlı, 0 Gizli ve 5 Misafir

Yok

[ Bütün listeye bak ]


Sitede bugüne kadar en çok 92 kişi Paz Ağus. 28, 2016 6:58 am tarihinde online oldu.
En son konular
» İnternetten Para Kazandıran Oyun ! Ödeme Alt Limiti Yok ! DEV KONU
Cuma Ağus. 29, 2014 8:33 am tarafından Hello EMO

» goldenchase.net maden yaparak para kazanma
Cuma Ağus. 29, 2014 8:18 am tarafından Hello EMO

» etichal hacker görsel egitim seti
Çarş. Ağus. 06, 2014 4:57 am tarafından Hello EMO

» KO TBL Source C#
Ptsi Ara. 09, 2013 6:36 am tarafından Hello EMO

» x86 Registers
C.tesi Ağus. 24, 2013 5:02 am tarafından Hello EMO

» [Tutorial] Pegando Address, Pointers de WYD
Çarş. Tem. 10, 2013 7:25 am tarafından Hello EMO

» [Tutorial] Pegando Address, Pointers de CS Metodo²
Çarş. Tem. 10, 2013 7:23 am tarafından Hello EMO

» [Tutorial] Aprendendo basico deASM OLLYDBG
Çarş. Tem. 10, 2013 7:22 am tarafından Hello EMO

» Basic C# DLL injector
Ptsi Tem. 08, 2013 7:48 am tarafından Hello EMO

Reklam

Http Post in C#

Önceki başlık Sonraki başlık Aşağa gitmek

Http Post in C#

Mesaj tarafından EMO Bir Perş. Haz. 02, 2011 4:28 am

Searched out on the internet and didn't really find anything that was
horribly succinct, so I wrote this class for fun. I had help from http://www.codeproject.com/cs/webservices/translation.asp. I hope you enjoy! Here's the code to call it:

Kod:
[size=9]PostSubmitter post=[/size][size=9][color=#0000ff]new[/color][/size][size=9] PostSubmitter();
post.Url="http://seeker.dice.com/jobsearch/servlet/JobSearch";
post.PostItems.Add("op","100");
post.PostItems.Add("rel_code","1102");
post.PostItems.Add("FREE_TEXT","c# jobs");
post.PostItems.Add("SEARCH","");
post.Type=PostSubmitter.PostTypeEnum.Post;
[/size][size=9][color=#0000ff]string[/color][/size][size=9] result=post.Post();[/size]
[size=9]And here's the class:[/size][size=9]
[size=9][color=#0000ff]using[/color][/size][size=9] System;
[/size][size=9][color=#0000ff]using[/color][/size][size=9] System.Text;
[/size][size=9][color=#0000ff]using[/color][/size][size=9] System.IO;
[/size][size=9][color=#0000ff]using[/color][/size][size=9] System.Web;
[/size][size=9][color=#0000ff]using[/color][/size][size=9] System.Net;
[/size][size=9][color=#0000ff]using[/color][/size][size=9] System.Collections.Specialized;[/size]
[size=9][color=#0000ff]namespace[/color][/size][size=9] Snowball.Common
{
[/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]<summary>
[/color][/size][size=9][color=#808080]///[/color][/size][size=9][color=#008000] Submits post data to a url.
[/color][/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]</summary>
[/color][/size][size=9][color=#0000ff]public[/color][/size] [size=9][color=#0000ff]class[/color][/size][size=9] PostSubmitter
{
[/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]<summary>
[/color][/size][size=9][color=#808080]///[/color][/size][size=9][color=#008000] determines what type of post to perform.
[/color][/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]</summary>
[/color][/size][size=9][color=#0000ff]public[/color][/size] [size=9][color=#0000ff]enum[/color][/size][size=9] PostTypeEnum
{
[/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]<summary>
[/color][/size][size=9][color=#808080]///[/color][/size][size=9][color=#008000] Does a get against the source.
[/color][/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]</summary>
[/color][/size][size=9]Get,
[/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]<summary>
[/color][/size][size=9][color=#808080]///[/color][/size][size=9][color=#008000] Does a post against the source.
[/color][/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]</summary>
[/color][/size][size=9]Post
}[/size]
[size=9][color=#0000ff]private[/color][/size] [size=9][color=#0000ff]string[/color][/size][size=9] m_url=[/size][size=9][color=#0000ff]string[/color][/size][size=9].Empty;
[/size][size=9][color=#0000ff]private[/color][/size][size=9] NameValueCollection m_values=[/size][size=9][color=#0000ff]new[/color][/size][size=9] NameValueCollection();
[/size][size=9][color=#0000ff]private[/color][/size][size=9] PostTypeEnum m_type=PostTypeEnum.Get;
[/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]<summary>
[/color][/size][size=9][color=#808080]///[/color][/size][size=9][color=#008000] Default constructor.
[/color][/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]</summary>
[/color][/size][size=9][color=#0000ff]public[/color][/size][size=9] PostSubmitter()
{
}[/size]
[size=9][color=#808080]///[/color][/size] [size=9][color=#808080]<summary>
[/color][/size][size=9][color=#808080]///[/color][/size][size=9][color=#008000] Constructor that accepts a url as a parameter
[/color][/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]</summary>
[/color][/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]<param name="url">[/color][/size][size=9][color=#008000]The url where the post will be submitted to.[/color][/size][size=9][color=#808080]</param>
[/color][/size][size=9][color=#0000ff]public[/color][/size][size=9] PostSubmitter([/size][size=9][color=#0000ff]string[/color][/size][size=9] url):[/size][size=9][color=#0000ff]this[/color][/size][size=9]()
{
m_url=url;
}[/size]
[size=9][color=#808080]///[/color][/size] [size=9][color=#808080]<summary>
[/color][/size][size=9][color=#808080]///[/color][/size][size=9][color=#008000] Constructor allowing the setting of the url and items to post.
[/color][/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]</summary>
[/color][/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]<param name="url">[/color][/size][size=9][color=#008000]the url for the post.[/color][/size][size=9][color=#808080]</param>
[/color][/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]<param name="values">[/color][/size][size=9][color=#008000]The values for the post.[/color][/size][size=9][color=#808080]</param>
[/color][/size][size=9][color=#0000ff]public[/color][/size][size=9] PostSubmitter([/size][size=9][color=#0000ff]string[/color][/size][size=9] url, NameValueCollection values):[/size][size=9][color=#0000ff]this[/color][/size][size=9](url)
{
m_values=values;
}[/size]
[size=9][color=#808080]///[/color][/size] [size=9][color=#808080]<summary>
[/color][/size][size=9][color=#808080]///[/color][/size][size=9][color=#008000] Gets or sets the url to submit the post to.
[/color][/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]</summary>
[/color][/size][size=9][color=#0000ff]public[/color][/size] [size=9][color=#0000ff]string[/color][/size][size=9] Url
{
[/size][size=9][color=#0000ff]get
[/color][/size][size=9]{
[/size][size=9][color=#0000ff]return[/color][/size][size=9] m_url;
}
[/size][size=9][color=#0000ff]set
[/color][/size][size=9]{
m_url=[/size][size=9][color=#0000ff]value[/color][/size][size=9];
}
}
[/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]<summary>
[/color][/size][size=9][color=#808080]///[/color][/size][size=9][color=#008000] Gets or sets the name value collection of items to post.
[/color][/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]</summary>
[/color][/size][size=9][color=#0000ff]public[/color][/size][size=9] NameValueCollection PostItems
{
[/size][size=9][color=#0000ff]get
[/color][/size][size=9]{
[/size][size=9][color=#0000ff]return[/color][/size][size=9] m_values;
}
[/size][size=9][color=#0000ff]set
[/color][/size][size=9]{
m_values=[/size][size=9][color=#0000ff]value[/color][/size][size=9];
}
}
[/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]<summary>
[/color][/size][size=9][color=#808080]///[/color][/size][size=9][color=#008000] Gets or sets the type of action to perform against the url.
[/color][/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]</summary>
[/color][/size][size=9][color=#0000ff]public[/color][/size][size=9] PostTypeEnum Type
{
[/size][size=9][color=#0000ff]get
[/color][/size][size=9]{
[/size][size=9][color=#0000ff]return[/color][/size][size=9] m_type;
}
[/size][size=9][color=#0000ff]set
[/color][/size][size=9]{
m_type=[/size][size=9][color=#0000ff]value[/color][/size][size=9];
}
}
[/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]<summary>
[/color][/size][size=9][color=#808080]///[/color][/size][size=9][color=#008000] Posts the supplied data to specified url.
[/color][/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]</summary>
[/color][/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]<returns>[/color][/size][size=9][color=#008000]a string containing the result of the post.[/color][/size][size=9][color=#808080]</returns>
[/color][/size][size=9][color=#0000ff]public[/color][/size] [size=9][color=#0000ff]string[/color][/size][size=9] Post()
{
StringBuilder parameters=[/size][size=9][color=#0000ff]new[/color][/size][size=9] StringBuilder();
[/size][size=9][color=#0000ff]for[/color][/size][size=9] ([/size][size=9][color=#0000ff]int[/color][/size][size=9] i=0;i < m_values.Count;i++)
{
EncodeAndAddItem([/size][size=9][color=#0000ff]ref[/color][/size][size=9] parameters,m_values.GetKey(i),m_values[i]);
}
[/size][size=9][color=#0000ff]string[/color][/size][size=9] result=PostData(m_url,parameters.ToString());
[/size][size=9][color=#0000ff]return[/color][/size][size=9] result;
}
[/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]<summary>
[/color][/size][size=9][color=#808080]///[/color][/size][size=9][color=#008000] Posts the supplied data to specified url.
[/color][/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]</summary>
[/color][/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]<param name="url">[/color][/size][size=9][color=#008000]The url to post to.[/color][/size][size=9][color=#808080]</param>
[/color][/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]<returns>[/color][/size][size=9][color=#008000]a string containing the result of the post.[/color][/size][size=9][color=#808080]</returns>
[/color][/size][size=9][color=#0000ff]public[/color][/size] [size=9][color=#0000ff]string[/color][/size][size=9] Post([/size][size=9][color=#0000ff]string[/color][/size][size=9] url)
{
m_url=url;
[/size][size=9][color=#0000ff]return[/color][/size] [size=9][color=#0000ff]this[/color][/size][size=9].Post();
}
[/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]<summary>
[/color][/size][size=9][color=#808080]///[/color][/size][size=9][color=#008000] Posts the supplied data to specified url.
[/color][/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]</summary>
[/color][/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]<param name="url">[/color][/size][size=9][color=#008000]The url to post to.[/color][/size][size=9][color=#808080]</param>
[/color][/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]<param name="values">[/color][/size][size=9][color=#008000]The values to post.[/color][/size][size=9][color=#808080]</param>
[/color][/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]<returns>[/color][/size][size=9][color=#008000]a string containing the result of the post.[/color][/size][size=9][color=#808080]</returns>
[/color][/size][size=9][color=#0000ff]public[/color][/size] [size=9][color=#0000ff]string[/color][/size][size=9] Post([/size][size=9][color=#0000ff]string[/color][/size][size=9] url, NameValueCollection values)
{
m_values=values;
[/size][size=9][color=#0000ff]return[/color][/size] [size=9][color=#0000ff]this[/color][/size][size=9].Post(url);
}
[/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]<summary>
[/color][/size][size=9][color=#808080]///[/color][/size][size=9][color=#008000] Posts data to a specified url. Note that this assumes that you have already url encoded the post data.
[/color][/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]</summary>
[/color][/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]<param name="postData">[/color][/size][size=9][color=#008000]The data to post.[/color][/size][size=9][color=#808080]</param>
[/color][/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]<param name="url">[/color][/size][size=9][color=#008000]the url to post to.[/color][/size][size=9][color=#808080]</param>
[/color][/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]<returns>[/color][/size][size=9][color=#008000]Returns the result of the post.[/color][/size][size=9][color=#808080]</returns>
[/color][/size][size=9][color=#0000ff]private[/color][/size] [size=9][color=#0000ff]string[/color][/size][size=9] PostData([/size][size=9][color=#0000ff]string[/color][/size][size=9] url, [/size][size=9][color=#0000ff]string[/color][/size][size=9] postData)
{
HttpWebRequest request=[/size][size=9][color=#0000ff]null[/color][/size][size=9];
[/size][size=9][color=#0000ff]if[/color][/size][size=9] (m_type==PostTypeEnum.Post)
{
Uri uri = [/size][size=9][color=#0000ff]new[/color][/size][size=9] Uri(url);
request = (HttpWebRequest) WebRequest.Create(uri);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postData.Length;
[/size][size=9][color=#0000ff]using[/color][/size][size=9](Stream writeStream = request.GetRequestStream())
{
UTF8Encoding encoding = [/size][size=9][color=#0000ff]new[/color][/size][size=9] UTF8Encoding();
[/size][size=9][color=#0000ff]byte[/color][/size][size=9][] bytes = encoding.GetBytes(postData);
writeStream.Write(bytes, 0, bytes.Length);
}
}
[/size][size=9][color=#0000ff]else
[/color][/size][size=9]{
Uri uri = [/size][size=9][color=#0000ff]new[/color][/size][size=9] Uri(url + "?" + postData);
[/size][size=9]request = (HttpWebRequest) WebRequest.Create(uri);
[/size][size=9]request.Method = "GET";
}
[/size][size=9][color=#0000ff]string[/color][/size][size=9] result=[/size][size=9][color=#0000ff]string[/color][/size][size=9].Empty;
[/size][size=9][color=#0000ff]using[/color][/size][size=9] (HttpWebResponse response = (HttpWebResponse) request.GetResponse())
{
[/size][size=9][color=#0000ff]using[/color][/size][size=9] (Stream responseStream = response.GetResponseStream())
{
[/size][size=9][color=#0000ff]using[/color][/size][size=9] (StreamReader readStream = [/size][size=9][color=#0000ff]new[/color][/size][size=9] StreamReader (responseStream, Encoding.UTF8))
{
result = readStream.ReadToEnd();
}
}
}
[/size][size=9][color=#0000ff]return[/color][/size][size=9] result;
}
[/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]<summary>
[/color][/size][size=9][color=#808080]///[/color][/size][size=9][color=#008000] Encodes an item and ads it to the string.
[/color][/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]</summary>
[/color][/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]<param name="baseRequest">[/color][/size][size=9][color=#008000]The previously encoded data.[/color][/size][size=9][color=#808080]</param>
[/color][/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]<param name="dataItem">[/color][/size][size=9][color=#008000]The data to encode.[/color][/size][size=9][color=#808080]</param>
[/color][/size][size=9][color=#808080]///[/color][/size] [size=9][color=#808080]<returns>[/color][/size][size=9][color=#008000]A string containing the old data and the previously encoded data.[/color][/size][size=9][color=#808080]</returns>
[/color][/size][size=9][color=#0000ff]private[/color][/size] [size=9][color=#0000ff]void[/color][/size][size=9] EncodeAndAddItem([/size][size=9][color=#0000ff]ref[/color][/size][size=9] StringBuilder baseRequest, [/size][size=9][color=#0000ff]string[/color][/size][size=9] key, [/size][size=9][color=#0000ff]string[/color][/size][size=9] dataItem)
{
[/size][size=9][color=#0000ff]if[/color][/size][size=9] (baseRequest==[/size][size=9][color=#0000ff]null[/color][/size][size=9])
{
baseRequest=[/size][size=9][color=#0000ff]new[/color][/size][size=9] StringBuilder();
}
[/size][size=9][color=#0000ff]if[/color][/size][size=9] (baseRequest.Length!=0)
{
baseRequest.Append("&");
}
baseRequest.Append(key);
baseRequest.Append("=");
baseRequest.Append(System.Web.HttpUtility.UrlEncode(dataItem));
}
}
}[/size][/size]

http://geekswithblogs.net/rakker/archive/2006/04/21/76044.aspx
avatar
EMO
EMO Team
EMO Team

Cinsiyet : Erkek
Burçlar : Yay
Yılan
Mesaj Sayısı : 184
Puan : 112043
Rep Puanı : 5
Doğum tarihi : 28/11/89
Kayıt tarihi : 18/05/11
Yaş : 27
Nerden : EMO world
İş/Hobiler : RCE Student / Game Hacking / Learn Beginner C#,C++,Delphi
Lakap : EMO

Kullanıcı profilini gör

Sayfa başına dön Aşağa gitmek

Geri: Http Post in C#

Mesaj tarafından EMO Bir Perş. Haz. 02, 2011 4:32 am

Ok.

I see a lot of people writing post-creator applications, which is a great way to start writing programs.

Here is a little guidance for those just starting out to help you along the way.


Thebold, italic, underline, code, img, quote, etc... buttons are very simple:


Code:

private void boldButton_Click(object sender, EventArgs e)
{
if (myRichTextBox.SelectionLength > 0)
"[b ]" + myRichTextBox.SelectedText + "[/b ]";
else
myRichTextBox.SelectedText = "[b ][/b ]";
}

Basically all that is saying is "if iv selected some text, wrap it
in the desired tags, else just put the tags wherever the cursor is".

The same process can be repeated for every button, or if you feel
daring, use the "object sender" as a reference and you can use one void
for all of the buttons.



One thing that you dont see very often is a "preview post" button, but its a very nice feature and is relatively simple:

Code:

private void PreviewSelectedPostButton_Click(object sender, EventArgs e)
{
string thePost = postContents.Text;

if (thePost.Length == 0)
{
MessageBox.Show(
"The post cannot be empty.",
"Empty Post",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
return;
}

// Line-Breaks
thePost = thePost.Replace("\n", "
");
// BOLD
thePost = thePost.Replace("[b ]", "");
thePost = thePost.Replace("[/b ]", "
");
// ITALIC
thePost = thePost.Replace("[i ]", "");
thePost = thePost.Replace("[/i ]", "
");
// UNDERLINE
thePost = thePost.Replace("[u ]", "");
thePost = thePost.Replace("[/u ]", "
");
// CODE box
thePost = thePost.Replace(
"[code ]",
"
");
thePost = thePost.Replace("[/code ]", "

");
// QUOTE box
thePost = thePost.Replace(
"[quote ]",
"
");
thePost = thePost.Replace("[/quote ]", "

");
// Images
thePost = thePost.Replace("[img ]", " thePost = thePost.Replace("[/img ]", "" />
");
// Colours
thePost = Regex.Replace(thePost, "\\[ color=(.*?)](.*?)\\[/color ]", "$2");

string htmlPath = System.Environment.CurrentDirectory + "\\preview.html";

using (StreamWriter writer = new StreamWriter(htmlPath))
{
writer.WriteLine("Multi-Poster Ultimate - Preview");
writer.WriteLine("
");
writer.Write(thePost);
writer.WriteLine("
");
}

System.Diagnostics.Process.Start(htmlPath);
}

What that's doing is using a simple string.replace method for most of the string replacements and regex for the harder color.
Its all wrapped in a 600px div to make it look more like it would when a post is sent to a forum.

Its then saved as a "html" file and then executed, and thus viewed in your default browser.

You will need to add the "System.IO" namespace for the StreamWriters and
also "System.Text.RegularExpressions" for the regex command.

And thats about it, nice and simple, and very useful to the user!

(Spaces have been added to the [TAGs] as not to get parsed )
avatar
EMO
EMO Team
EMO Team

Cinsiyet : Erkek
Burçlar : Yay
Yılan
Mesaj Sayısı : 184
Puan : 112043
Rep Puanı : 5
Doğum tarihi : 28/11/89
Kayıt tarihi : 18/05/11
Yaş : 27
Nerden : EMO world
İş/Hobiler : RCE Student / Game Hacking / Learn Beginner C#,C++,Delphi
Lakap : EMO

Kullanıcı profilini gör

Sayfa başına dön Aşağa gitmek

Önceki başlık Sonraki başlık Sayfa başına dön

- Similar topics

 
Bu forumun müsaadesi var:
Bu forumdaki mesajlara cevap veremezsiniz