2

I am developing IE addon and now a problem occurred. I surfed the google alot but no solution i found. The problem is i am sending a post httpwebrequest from my C# addon to another server and getting the response from that server. now i want to send more than one requests from single form. the first request i am sending is working well but when i press the second button to send httpwebrequest again, it gives me the error.

Here is my code :

public string postdata(string url, string data)
{
        string result = null;
        // Create the web request  
        HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
        request.Method = "POST";
        request.ContentType = "application/x-www-form-urlencoded";

        using (Stream s = request.GetRequestStream())
        {
            using (StreamWriter sw = new StreamWriter(s))
            sw.Write(data);

        }
        // Get response  
        using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
        {
            // Get the response stream  
            StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);

            // Read the whole contents and return as a string  
            result = reader.ReadToEnd();
        }
        return result;
}

Calling the method :

string url ="abc.com/abc_controller/abc_function"; // Codeigniter Website url
string data = "fn_name=TEMP&city=Delhi";
abctextbox.Text = postdata(url, data);

Can anyone please help me on this issue.

Thanks in advance.

invidicult
  • 306
  • 2
  • 8
  • 19
Mann Verma
  • 111
  • 8
  • 6
    What error does it give? – Yuval Itzchakov May 28 '15 at 07:48
  • "Unhandled exception has occurred in a component in your application. if you click Continue, the application will ignore this error and attempt to continue. The remote server returned an error: (406) Not Applicable." This error message comes in an error dialog box. – Mann Verma May 28 '15 at 08:11
  • We need more detail. Post the *actual* error message and stack trace. – Yuval Itzchakov May 28 '15 at 08:12
  • @Yuval Itzchakov i saw the warning traced on error list on .Net Studio. The warning is: `"Could not copy 'obj\Debug\iKeypassAddon.dll' to 'bin\Debug\iKeypassAddon.dll'. Beginning retry 1 in 1000ms. The process cannot access the file 'bin\Debug\iKeypassAddon.dll' because it is being used by another process. iKeypassAddon "` – Mann Verma May 28 '15 at 08:18
  • This isn't the problem. You're mixing two unrelated errors. – Yuval Itzchakov May 28 '15 at 08:20
  • @Yuval Itzchakov i think i know the main issue. i.e the request i am sending is taking much request time and during this process i send the second request. then it gives the error. – Mann Verma May 28 '15 at 09:40
  • Possible duplicate of [Max number of concurrent HttpWebRequests](http://stackoverflow.com/questions/1361771/max-number-of-concurrent-httpwebrequests) – Paul Sweatte Aug 01 '16 at 14:29

0 Answers0