why when i try to send http post , my Project for a few sec send not responding
my code
string ResP = "";
System.Net.WebRequest req = System.Net.WebRequest.Create(URI);
req.ContentType = "application/x-www-form-urlencoded";
req.Method = "POST";
byte[] bytes = System.Text.Encoding.ASCII.GetBytes(Parameters);
req.ContentLength = bytes.Length;
System.IO.Stream os = req.GetRequestStream();
os.Write(bytes, 0, bytes.Length);
os.Close();
System.Net.WebResponse resp = req.GetResponse();
System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
ResP = sr.ReadToEnd().Trim();
7 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Ashutosh PathakPosted Jul 17, 2014, 3:59 AM
Below is the solution where i used thread to resolve the problem try and see if it helps:
Ashutosh PathakPosted Jul 21, 2014, 11:33 AM
you can write this
but this code cannot give the guarantee of web request response order hence you have to observe in a loop that all responses are captured and all values are set in responseResult object then you can easily iterate in this array and set your text in textbox
XIII XIIIPosted Jul 17, 2014, 6:53 PM
how i can put result in TextBox in ur code?
XIII XIIIPosted Jul 16, 2014, 4:29 PM
tnx bro For answering <3
Ashutosh PathakPosted Jul 16, 2014, 3:27 AM
Before return the response in HttpPost function try adding this to your code and see if it helps:
resp.Close();
XIII XIIIPosted Jul 15, 2014, 5:22 PM
for e.g
}
//////////////////////////////////////////////////////////////////////////////////////
public static string HttpPost(string URI, string Parameters, string PROXY)
WebProxy Prxy = new WebProxy(PROXY, true) ;
req.Proxy = PROXY;
return ResP;
}
Ashutosh PathakPosted Jul 15, 2014, 10:36 AM
-----------------------------------------------------------------------------------------
string field1 = "abcd";
string Parameters = "field1=" + field1;
string ResP = "";
System.Net.WebRequest req = System.Net.WebRequest.Create("http://localhost:25128/WebForm1.aspx");
req.ContentType = "application/x-www-form-urlencoded";
req.Method = "POST";
byte[] bytes = System.Text.Encoding.ASCII.GetBytes(Parameters);
req.ContentLength = bytes.Length;
System.IO.Stream os = req.GetRequestStream();
os.Write(bytes, 0, bytes.Length);
os.Close();
System.Net.WebResponse resp = req.GetResponse();
System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
ResP = sr.ReadToEnd().Trim();
--------------------------------------------------------------------------------------------------
/* code for web page WebForm1.aspx*/
protected void Page_Load(object sender, EventArgs e)
{
HttpContext.Current.Response.Write("Ashutosh");
}