[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Post to PHP

Posted on 2005-05-13
3
Medium Priority
?
253 Views
Last Modified: 2010-04-23
As simple as this: I want to post some data to my PHP form on the internet. At the moment I have it doing it through a webbrowser control, inputting the text into a form and artificially pressing the "submit" button. This doesn't seem to be very reliable, so what other, more reliable method should I use?

Thanks a lot :-). Let me know if you need clarification.
0
Comment
Question by:robert4532
3 Comments
 
LVL 13

Accepted Solution

by:
softplus earned 1000 total points
ID: 13994209
I assume you want to upload a file in a POST request, is that correct? Or do you just want to fill out some fields on a form? (would be easier)

This is to upload a file: Is C# ok? it's easy to convert :) - if this is a problem, let me know.


try
{ FileStream objfilestream = new FileStream
(inputFile.Value,FileMode.Open,FileAccess.Read);
int len = (int)objfilestream.Length;
Byte[] buffer = new Byte[len];
objfilestream.Read(buffer,0,len);
objfilestream.Close();
// create the Http Request
StringBuilder requestStream = new System.Text.StringBuilder();
for(int i = 0; i < buffer.Length; i++)
{ requestStream.Append(string.Format("file={0}", buffer[i]
) + ((i < buffer.Length - 1 && buffer.Length > 1) ? "&" :
string.Empty));
}
requestStream.Append(String.Format("&name={0}",txtName.Text));
UTF8Encoding encoding = new UTF8Encoding();
byte[] requestStreambuffer = encoding.GetBytes(requestStream.ToString()
);
HttpWebRequest httpRequest = (HttpWebRequest)
HttpWebRequest.Create("http://someserver/upload.php");
httpRequest.Method = "POST";
httpRequest.KeepAlive = true;
httpRequest.ContentType = "application/x-www-form-urlencoded";
httpRequest.ContentLength = requestStreambuffer.Length;
httpRequest.Timeout = 30000;
httpRequest.GetRequestStream().Write(requestStreambuffer, 0,
requestStreambuffer.Length); httpRequest.GetRequestStream().Close();
} catch(Exception exp) { Console.WriteLine(string.Format
("Error: {0}", exp.Message)); }
0
 

Author Comment

by:robert4532
ID: 13999016
I just want to fill out some fields on a form, expect without actually filling them out manually (submitting directly to the page that process the post).

Thanks.
0
 

Expert Comment

by:DonGarry
ID: 15118166
Would it be possible to get the above solution in VB ? I'm really not familiar with C#.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month19 days, 18 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question