473,396 Members | 1,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Post Request and C#

Ori
Hi,

I need to implement the following.

I need to perform a web request (only post methods), but I also need
to send some parameters values with this request.

Can I do it using the WebRequest class (using "POST" method only)?

In the same time I have another question. I need to perform this
request to a File.exe file (the URL which I'm doing this request to
has a fileName.exe in the end of the url). Can i pass a parameters to
the .exe file using "GET" method or post is the only method which I
can use in this case.

Thanks,

Ori.
Nov 15 '05 #1
5 45434
> Can I do it using the WebRequest class (using "POST" method only)?

HttpWebRequest HttpWReq =
(HttpWebRequest)WebRequest.Create(
"http:\\www.blabla.com\services\service1.asp"
);

ASCIIEncoding encoding=new ASCIIEncoding();
string postData="username=foo";
postData += ( "&password=boo");
byte[] data = encoding.GetBytes(postData);

HttpWReq.Method = "POST";
HttpWReq.ContentType = "application/x-www-form-urlencoded";
HttpWReq.ContentLength = data.Length;

Stream newStream = HttpWReq.GetRequestStream();
newStream.Write(data,0,data.Length);
newStream.Close();

Luca Paganelli
Nov 15 '05 #2
Perhaps you are interested also looking at the WebClient Class

If you have to "post" some values, like a form submit, it has a very nice
method:

WebClient.UploadValues(...);

"Ori" <or*******@hotmail.com> schrieb im Newsbeitrag
news:b4**************************@posting.google.c om...
Hi,

I need to implement the following.

I need to perform a web request (only post methods), but I also need
to send some parameters values with this request.

Can I do it using the WebRequest class (using "POST" method only)?

In the same time I have another question. I need to perform this
request to a File.exe file (the URL which I'm doing this request to
has a fileName.exe in the end of the url). Can i pass a parameters to
the .exe file using "GET" method or post is the only method which I
can use in this case.

Thanks,

Ori.

Nov 15 '05 #3


do you some examples for WebClient.UploadValues(...); ?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #4
Example from:
http://msdn.microsoft.com/library/de...aluestopic.asp

[C#]
Console.Write("\nPlease enter the URL to post data to : ");
string uriString = Console.ReadLine();

// Create a new WebClient instance.
WebClient myWebClient = new WebClient();

// Create a new NameValueCollection instance to hold some custom parameters
to be posted to the URL.
NameValueCollection myNameValueCollection = new NameValueCollection();

Console.WriteLine("Please enter the following parameters to be posted to the
URI");
Console.Write("Name:");
string name = Console.ReadLine();

Console.Write("Age:");
string age = Console.ReadLine();

Console.Write("Address:");
string address = Console.ReadLine();

// Add necessary parameter/value pairs to the name/value container.
myNameValueCollection.Add("Name",name);
myNameValueCollection.Add("Address",address);
myNameValueCollection.Add("Age",age);
Console.WriteLine("\nUploading to {0} ...", uriString);

// Upload the NameValueCollection.
byte[] responseArray =
myWebClient.UploadValues(uriString,"POST",myNameVa lueCollection);

// Decode and display the response.
Console.WriteLine("\nResponse received was
:\n{0}",Encoding.ASCII.GetString(responseArray));

"Ori Anavim" <an********@hotmail.com> schrieb im Newsbeitrag
news:OA****************@TK2MSFTNGP11.phx.gbl...


do you some examples for WebClient.UploadValues(...); ?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 15 '05 #5
Well, to put my few lines into that topic. I suppose, that a bigger problem is to find out how to really READ the values in the CGI application than how to send them.

There are plenty of samples how to send GET or POST requests. But how to get them in CGI exe application written in .Net.

Let me present a sample code how to handle the sent values with a GET method to a CGI C# application in a sample console application:

using System;

namespace CGITest
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
string queryString = Environment.GetEnvironmentVariable("QUERY_STRING") ;

Console.WriteLine("Content-Type:text/html\n");

Console.WriteLine ("QUERY_STRING: " + queryString);

}
}
}

I didn't manage to find any samples or sort out how to read the values sent with a POST method. Will keep on searching. If anyone knows, just let us know.

--
Cezary Nolewajka
mailto:c.*********************@no-sp-am-eh-mail.com
remove all "no-sp-am-eh"s to reply

"Ori" <or*******@hotmail.com> wrote in message news:b4**************************@posting.google.c om...
Hi,

I need to implement the following.

I need to perform a web request (only post methods), but I also need
to send some parameters values with this request.

Can I do it using the WebRequest class (using "POST" method only)?

In the same time I have another question. I need to perform this
request to a File.exe file (the URL which I'm doing this request to
has a fileName.exe in the end of the url). Can i pass a parameters to
the .exe file using "GET" method or post is the only method which I
can use in this case.

Thanks,

Ori.

Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Pavils Jurjans | last post by:
Hallo, I am working on multilingual web-application, and I have to be very sure about how the international characters are encoded and decoded in the client-server form requests. There's a...
3
by: reneeccwest | last post by:
How can I simulate HTTP post request by JavaScript? When I select from <SELECT> combo box. onClick will call JavaScript function. I want this function to send HTTP POST request with the selected...
2
by: Robert Oschler | last post by:
I am working on a PHP 4 app that interacts with an external authorization server. The external server does "third-party" authorization of users. So I do the following: 1) Each of my PHP scripts...
4
by: James Johnson | last post by:
Dear C#Dex, I am trying to automate a POST to a web page that clicks a button. I have been able to hit a target web page and run the web page. However, the button on the page does not click. ...
6
by: Clif | last post by:
Hi, I would like to find out exactly what is being sent when a web page uses the post request method. My thought was to use the webbrowser control together with the HTTPWebRequest class, but am...
7
by: Carl | last post by:
these are three files below : submit.html <html> <head> </head> <body> <form action="redirect.php" method="POST" > <input type="text" name="value" value="test" > <input type="submit" >...
0
by: guddi1 | last post by:
Hi, I am looking to figure out how to display parameters of a post request. I am working in visual C++ environment. I have a program that tracks and outputs URL activity. For instance, when I log...
2
by: Samuel Shulman | last post by:
I have to create a page that all it does it handle a 'POST' request with some parameters So I created a blank page and in the Load event I try to handle the parameters passed but the page...
2
by: MDANH2002 | last post by:
Hi From VB.NET I want to simulate the POST request of the following HTML form <html> <title>HTTP Post Testing</title> <body> <form action=http://www.example.com/postdata ...
6
by: 703designs | last post by:
I'm writing a little Drupal module that implements a couple forms, relaying the submitted values to a third-party site. I know the target URL and I have all of the values that I want to submit with...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.