Hi,

I have a problem with a webrequest with the below code.
If I try to request "http://www.google.com", it works fine.

But when I try to reach this long URL below with this code, I receive an error:

I wonder what this depends on and what could be done?

The remote server returned an error: (400) Bad Request."

//HttpWebRequest^ myRequest = (HttpWebRequest^)WebRequest::Create("http://www.google.com");
HttpWebRequest^ myRequest = (HttpWebRequest^)WebRequest::Create("http://www.xxxxxxxxxxxxxxx.com/en/trading/exchanges.php?exch=arcaedge&showcategories=STK&showproducts=All&sequence_idx=100&sortproducts=&ib_entity=uk#show");

myRequest->Method = "GET";
myRequest->Timeout = 10000;
WebResponse^ myResponse = myRequest->GetResponse();

StreamReader^ sr = gcnew StreamReader(myResponse->GetResponseStream(), System::Text::Encoding::UTF8);
String^ result = sr->ReadToEnd();
result = result->ToLower(); //make to lower
sr->Close();
            
MessageBox::Show(result);

Recommended Answers

All 3 Replies

If you drop off the #show, does it work?
Nevermind. It even fails at the root URL.
Investigating...

If you drop off the #show, does it work?
Nevermind. It even fails at the root URL.
Investigating...

I found the solution by adding a parameter like this to accept:

myRequest->Accept = "image/*";
myRequest->UserAgent = "User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; SV1; SearchToolbar 1.2; .NET CLR 2.0.50727; .NET4.0C; .NET4.0E; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)";

Wow, good job!

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.