Hi there, got following problem: I want to upload a large amount of image data to the server. Once this is done, I need to start a script on the server to process the data (in this case, it's python). I could start the script with a parameterized call. So
my question is, how would I build the url and send it automatically after the upload is complete. I'm using if(IsPost) and a counter to upload the images. I think I can not use the action parameter in the form tag. Am i right?
Thank you for your help. I'm new in programming, so sorry for my questions. I got an error in the following three lines: (the name encoding is not available in the actual context...)
byte[] buffer = Encoding.UTF8.GetBytes(data);
req.ContentLength = buffer.Length;
reqst.Write(buffer, 0, buffer.Length);
Is there a possibility to set up a simple site to test, how the post gets submitted?
being_mp
Member
42 Points
26 Posts
How to call a URL(script) after post
Feb 21, 2012 12:16 PM|LINK
Hi there, got following problem: I want to upload a large amount of image data to the server. Once this is done, I need to start a script on the server to process the data (in this case, it's python). I could start the script with a parameterized call. So my question is, how would I build the url and send it automatically after the upload is complete. I'm using if(IsPost) and a counter to upload the images. I think I can not use the action parameter in the form tag. Am i right?
Thanks for the help.
post url upload
smirnov
All-Star
23586 Points
4049 Posts
Re: How to call a URL(script) after post
Feb 21, 2012 05:21 PM|LINK
Can't you just use a redirect from the code behind?
Response.Redirect("script.py");
being_mp
Member
42 Points
26 Posts
Re: How to call a URL(script) after post
Feb 21, 2012 06:52 PM|LINK
I have to send a few parameters from user-input to the script. I think that's not possible with the redirect.
smirnov
All-Star
23586 Points
4049 Posts
Re: How to call a URL(script) after post
Feb 22, 2012 01:59 AM|LINK
If script accepts parameters from a query string, use "script.py?x=1&y=2". In other case, use HTTP POST
string url = "http://..."; HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); string proxy = null; string data = String.Format("parameter1={0}¶meter2={1}¶meter3={2}", parameter1, parameter2, parameter3); byte[] buffer = Encoding.UTF8.GetBytes(data); req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; req.ContentLength = buffer.Length; req.Proxy = new WebProxy(proxy, true); // ignore for local addresses req.CookieContainer = new CookieContainer(); // enable cookies Stream reqst = req.GetRequestStream(); // add form data to request stream reqst.Write(buffer, 0, buffer.Length); reqst.Flush(); reqst.Close(); HttpWebResponse res = (HttpWebResponse)req.GetResponse(); Stream resst = res.GetResponseStream(); StreamReader sr = new StreamReader(resst); string response = sr.ReadToEnd();Hope this helps.
being_mp
Member
42 Points
26 Posts
Re: How to call a URL(script) after post
Feb 22, 2012 08:16 AM|LINK
Thank you for your help. I'm new in programming, so sorry for my questions. I got an error in the following three lines: (the name encoding is not available in the actual context...)
byte[] buffer = Encoding.UTF8.GetBytes(data);
req.ContentLength = buffer.Length;
reqst.Write(buffer, 0, buffer.Length);
Is there a possibility to set up a simple site to test, how the post gets submitted?
rabindra_lal
Member
515 Points
202 Posts
Re: How to call a URL(script) after post
Feb 22, 2012 08:20 AM|LINK
Please visit this link
http://msdn.microsoft.com/en-us/magazine/cc163941.aspx
post url upload
smirnov
All-Star
23586 Points
4049 Posts
Re: How to call a URL(script) after post
Feb 22, 2012 01:38 PM|LINK
You need to add system.text namespace in your class.
using System.Text;
Regarding test script. Suppose you're posting a variable called "username"
If using .cgi
if using .py: