Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7961875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:10:23+00:00 2026-06-04T05:10:23+00:00

I have this code: private HttpWebRequest request; private HttpWebResponse wResponse; private CookieContainer cookieContainer =

  • 0

I have this code:

        private HttpWebRequest request;
        private HttpWebResponse wResponse;
        private CookieContainer cookieContainer = new CookieContainer();
        #region PRIVATE METHODS
        private void RunRequest(string url)
        {
            request = HttpWebRequest.Create(new Uri(url)) as HttpWebRequest;
            request.UserAgent = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.205 Safari/534.16";
            request.ContentType = "application/x-www-form-urlencoded";
            request.CookieContainer = cookieContainer;
            request.Method = "GET";

            StartWebRequest(request);

            //Do smthng
            while (wResponse == null) { }
        }

        private void StartWebRequest(HttpWebRequest request)
        {
            request.BeginGetResponse(FinishWebRequest, request);
        }

        private void FinishWebRequest(IAsyncResult result)
        {
            wResponse = (result.AsyncState as HttpWebRequest).EndGetResponse(result) as HttpWebResponse;
        }
        #endregion

And wRequest variable is not filled with any response. In AsyncState I have this:
HttpWebRequest error

What could be the problem?

p.s. The same code works good on the desktop-app.

Thanks,
Pavel.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T05:10:25+00:00Added an answer on June 4, 2026 at 5:10 am

    There are two problems in your code.

    1. You are not properly using asynchronous callback method:

      Replace

      request.BeginGetResponse(FinishWebRequest, request);

      with

      request.BeginGetResponse(new AsyncCallback(FinishWebRequest), request);

    2. Specifying Content-Type for GET request is invalid, it is essential
      for POST request. Modify RunRequest() method:

      private void RunRequest(string url, string method)
      {
          request = HttpWebRequest.Create(new Uri(url)) as HttpWebRequest;
          request.UserAgent = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.205 Safari/534.16";
          request.Method = method; // method can be GET, POST etc.
          if (method == "POST")
              request.ContentType = "application/x-www-form-urlencoded";
          request.CookieContainer = cookieContainer;
          ...
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code private void writeReport(IReport report, string reportName) { string reportString =
I have this code private void saveImage() { Bitmap bmp1 = new Bitmap(pictureBox.Image); bmp1.Save(c:\\t.jpg,
I have this code: private static void saveMetricsToCSV(String fileName, double[] metrics) { try {
I have this code : private void insertValus() { ContentValues initialValues = new ContentValues();
I have this code: private void SaveStreamToFile(string fileFullPath, Stream stream) { if (stream.Length ==
I have this code: private void doSomething() throws InterruptedException { WorkerThread w= new WorkerThread(this);
I have this code: private class DownloadWebPageTask extends AsyncTask<String, Void, String> { @Override protected
I have this code: private void timer1_Tick(object sender, EventArgs e) { #region BaseAddress Process[]
I have this code: private static readonly Dictionary<string, ChatUser> _users = new Dictionary<string, ChatUser>(StringComparer.OrdinalIgnoreCase);
I have this snippet of code private Templates retrieveFromCache(String name) { TemplatesWrapper t =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.