how do I send a post string

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do i send a post string in c# .net cf
i need to send a multipart/form-data to a web server and get its response
 
Use HttpWebRequest.GetRequestStream and then write into that stream. Close
it when you are done. Might be easier to create a StreamWriter on it with
appropriate encoding
Something like this:

Uri target = new Uri(args[0]);
HttpWebRequest req = HttpWebRequest.Create(target) as HttpWebRequest;
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
Stream st = req.GetRequestStream();
StreamWriter wrt = new StreamWriter(st, Encoding.ASCII);
wrt.Write("destination=" + args[0]);
wrt.Write("&flags=14"); // Rich client (1 - basic client)
Console.Write("user: ");
wrt.Write("&username=" + Console.ReadLine());
Console.Write("password: ");
wrt.Write("&password=" + Console.ReadLine());
wrt.Write("&submit=submit");
wrt.Close();
st.Close();
HttpWebResponse rsp = req.GetResponse() as HttpWebResponse;
st = rsp.GetResponseStream();
StreamReader rdr = new StreamReader(st);
Console.WriteLine(rdr.ReadToEnd());
 
I need something that will send a post string like this:

POST /example-test/example.php HTTP/1.1
Host: don
Connection: Keep-Alive, TE
TE: trailers, deflate, gzip, compress
User-Agent: RPT-HTTPClient/0.3-3E
Cookie: GallerySession=4ca4085148c93f808cb620e515245974
Cookie2: $Version="1"
Accept-Encoding: deflate, gzip, x-gzip, compress, x-compress
Content-type: multipart/form-data;
boundary=--------ieoau._._+2_8_GoodLuck8.3-ds0d0J0S0Kl234324jfLdsjfdAuaoei-----
Content-length: 43183

----------ieoau._._+2_8_GoodLuck8.3-ds0d0J0S0Kl234324jfLdsjfdAuaoei-----
Content-Disposition: form-data; name="cmd"

add-item
----------ieoau._._+2_8_GoodLuck8.3-ds0d0J0S0Kl234324jfLdsjfdAuaoei-----
Content-Disposition: form-data; name="protocol_version"

2.3
----------ieoau._._+2_8_GoodLuck8.3-ds0d0J0S0Kl234324jfLdsjfdAuaoei-----
Content-Disposition: form-data; name="set_albumName"

test1
----------ieoau._._+2_8_GoodLuck8.3-ds0d0J0S0Kl234324jfLdsjfdAuaoei-----
Content-Disposition: form-data; name="caption"


----------ieoau._._+2_8_GoodLuck8.3-ds0d0J0S0Kl234324jfLdsjfdAuaoei-----
Content-Disposition: form-data; name="force_filename"

bridge.jpg
----------ieoau._._+2_8_GoodLuck8.3-ds0d0J0S0Kl234324jfLdsjfdAuaoei-----
Content-Disposition: form-data; name="userfile"; filename="res-1265080177.jpg"
Content-Type: image/jpeg

*** a whole bunch of data: the contents of the file, in binary format ***
----------ieoau._._+2_8_GoodLuck8.3-ds0d0J0S0Kl234324jfLdsjfdAuaoei-------


Alex Feinman said:
Use HttpWebRequest.GetRequestStream and then write into that stream. Close
it when you are done. Might be easier to create a StreamWriter on it with
appropriate encoding
Something like this:

Uri target = new Uri(args[0]);
HttpWebRequest req = HttpWebRequest.Create(target) as HttpWebRequest;
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
Stream st = req.GetRequestStream();
StreamWriter wrt = new StreamWriter(st, Encoding.ASCII);
wrt.Write("destination=" + args[0]);
wrt.Write("&flags=14"); // Rich client (1 - basic client)
Console.Write("user: ");
wrt.Write("&username=" + Console.ReadLine());
Console.Write("password: ");
wrt.Write("&password=" + Console.ReadLine());
wrt.Write("&submit=submit");
wrt.Close();
st.Close();
HttpWebResponse rsp = req.GetResponse() as HttpWebResponse;
st = rsp.GetResponseStream();
StreamReader rdr = new StreamReader(st);
Console.WriteLine(rdr.ReadToEnd());


--
Alex Feinman
---
Visit http://www.opennetcf.org
Don Andrez said:
How do i send a post string in c# .net cf
i need to send a multipart/form-data to a web server and get its response
 
Back
Top