I have this code:

HttpWebRequest request = (HttpWebRequest) WebRequest.Create(someUrl);
request.Accept = "*/*";///////////
request.CookieContainer = cookies;
request.Method = sendVerb;
request.CachePolicy = new RequestCachePolicy(RequestCacheLevel.Reload);
request.AllowAutoRedirect = false;
request.KeepAlive = true;

When I'm in GET mode, in this line, the program crashes:

using (HttpWebResponse responseData = (HttpWebResponse)request.GetResponse())

The information in the catch block says:
The remote server returned an error: (403) Forbidden.

When I'm in GET mode, in this line, the program crashes:

using (HttpWebResponse responseData = (HttpWebResponse)request.GetResponse())

The information in the catch block says:
The remote server returned an error: (403) Forbidden.

This could be a permissions problem on the Web server... what is the URL you're trying to get, and can you view it normally in a browser?

Yes, I can view it when I write the url in a browser directly.
The url is someSite/login.php

Yes, I can view it when I write the url in a browser directly.
The url is someSite/login.php

Hmmm... try setting the request.UserAgent property. Make up your own string first--if that works, fine; if not, try one of the example user agent strings in the MSDN page I linked.

The problem gets when the window for sending the message gets to "Searching...".
I'm sending issues on a mantis web site.
I have a method CheckModify(string html) which checks if the html string contains "view.php?id=". If view.php link is found, some bug exists.
Can someone explain why? The code isn't mine.

The problem gets when the window for sending the message gets to "Searching...".

What window are we talking about here? So far, we've only been talking about HttpWebRequest , which doesn't provide any UI.

I'm sending issues on a mantis web site.

So your code is submitting an issue to a Mantis site? Is that still a GET ? It's been a while since I've worked with Mantis.

I have a method CheckModify(string html) which checks if the html string contains "view.php?id=". If view.php link is found, some bug exists.
Can someone explain why? The code isn't mine.

Can you post some code? It's not very clear what you're asking here.

Okay, I'll add more detail tomorrow, I don't have the code now.

The problem is the function CheckModify(string html) which should return true.
This method returns false because the html string which is its parameter, contains "view.php?id=". One comment says that if html contains "view.php?id=", then a bug exists which cannot be edited.

private bool CheckModify(string html)
        {
            int recentlyVisitedBlockStartPosition = html.IndexOf("<small>Recently Visited");
            int mainTextStart = 0;

            if (recentlyVisitedBlockStartPosition != -1)
                mainTextStart = html.IndexOf("</small>", recentlyVisitedBlockStartPosition);

            return html.IndexOf("view.php?id=", mainTextStart) == -1;
        }
private bool CheckModify(string html)
        {
            int recentlyVisitedBlockStartPosition = html.IndexOf("<small>Recently Visited");
            int mainTextStart = 0;

            if (recentlyVisitedBlockStartPosition != -1)
                mainTextStart = html.IndexOf("</small>", recentlyVisitedBlockStartPosition);

            return html.IndexOf("view.php?id=", mainTextStart) == -1;
        }

If CheckModify is returning false , that means it found "view.php?id=" somewhere in the page. I'm not too convinced by the "Recently Visited" detection code; it may not be detecting that section correctly and returning false because it found something that it should have skipped.

Can you post some of the HTML that is causing CheckModify to behave unexpectedly?

http://www.mantisbt.org/demo/my_view_page.php

Well, that explains it.

The text "<small>Recently Visited" isn't there, and I count 25 separate instances of "view.php?id=" scattered throughout the page. So CheckModify should, as written, return false for this page.

Next step is to figure out what CheckModify is really there for, as in why are we checking for "view.php?id=" in the page? If it's commented, great; if not, you have some analysis to do.

I'm sorry, in the html file which is argument of this method there is "Recently visited".

I'm sorry, in the html file which is argument of this method there is "Recently visited".

For you, maybe. It's a PHP file, so the HTML is generated on the fly by the server. Visit it in your browser, save it as HTML, and post it here. Then we'll be talking about the same thing.

Here.

In the HTML you linked, the string "view.php?id=" shows up quite a few times, both inside the "<small>Recently Visited" ... </small> section and outside of it. As a result, CheckModify is returning false , which means it is working as designed.

As I'm not familiar with the codebase you're working with, I can't say why CheckModify was designed that way or what it's really supposed to mean. If there are any comments or other documentation, that would be the place to start.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.