Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / April 2007

Tip: Looking for answers? Try searching our database.

How to submit a POST with a WebRequest? (in C# to a PHP file)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lloyd Dupont - 24 Apr 2007 02:34 GMT
there is a PHP file with which I try to communicate.
there is a simple HTML like that:
"<form action='feedback.php' method='POST'>blablabl</form>"

now I try to write some C# code to invoke the PHP from a desktop app, which
look like that:
====================
 static HttpWebRequest CreateRequest(string url, string method,
IDictionary<string, string> parameters, Stream data)
 {
  HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  request.Method = method;

  foreach (string key in parameters.Keys)
   request.Headers.Add(key, parameters[key]);

  using (Stream reqStream = request.GetRequestStream())
  {
   //request.Headers.Add("Content-Length:", reqStream.Length.ToString());
   CopyStream(data, reqStream);
  }

  return request;
 }
====================
where URL is the URL of the PHP page.
unfortunately nothin is picked up by the PHP script.

did I miss something?
how do I submit multiple file btw?
Siva M - 24 Apr 2007 06:12 GMT
Try setting the ContentType property of the HttpWebRequest instance to
"application/x-www-form-urlencoded". Also, set the ContentLength to the
actual size of data being written to.

> there is a PHP file with which I try to communicate.
> there is a simple HTML like that:
[quoted text clipped - 26 lines]
> did I miss something?
> how do I submit multiple file btw?
bruce barker - 24 Apr 2007 16:41 GMT
its unlikely that the php page is expecting the parameters as page
headers. its probably expecting a standard browser form post
(content-type=application/x-ww-form-urlencoded). th data is sent as name
value pairs (name=value) with "&" as a seperator. the name and value
should be urlencoded.

if you want to send a file, then the page is expecting a content-type:
multipart/mixed; boundary="myboundrystring". then standard mime headers
with content. (depends on type), delimted by boundary strings

google either mime type for more info.

-- bruce (sqlwork.com)

> there is a PHP file with which I try to communicate.
> there is a simple HTML like that:
[quoted text clipped - 26 lines]
> did I miss something?
> how do I submit multiple file btw?
Lloyd Dupont - 26 Apr 2007 02:53 GMT
thanks bruce

Signature

Regards,
Lloyd Dupont
NovaMind Software
Mind Mapping at its best
www.nova-mind.com

> its unlikely that the php page is expecting the parameters as page
> headers. its probably expecting a standard browser form post
[quoted text clipped - 40 lines]
>> did I miss something?
>> how do I submit multiple file btw?

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.