The url zvoxaudio.com, from your comments, is pretty complicated. They have some bot detection for adding items to the basket. The link you are using does not seem to work regardless of the fact that, I think, it uses an id with an expired number; I was able to use it by updating id to 4007001 and changing it to "https". However, this link adds an item to the cart, and the site does not allow bots to add items to the cart, the site returns an error 400 with this key: value in the headers:
X-Error-Message: Bots are not allowed to add items to cart
Try adding UserAgent to your query as follows:
myRequest.UserAgent = "Nada";
The ZVOXAUDIO link works with these small changes!
If you want to save the URL as an "https" request, just add it to your code.
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
This is required because ZVOXAUDIO does not support TLS 1.0 or earlier. If the .NET version you are using does not support TLS 1.2, you can use SecurityProtocolType.Tls11, because ZVOXAUDIO still supports TLS 1.1.
But since, apparently, you are trying to run this launch on as many sites as possible, you probably do not want to allow only TLS 1.2, as older servers may not support it. I would set the security protocol as follows:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls | SecurityProtocolType.Ssl3;
As a suggestion, you can set the server certificate verification callback and the security protocol outside of your loop, since it is a static parameter for all requests. Also, if you use C # syntax, the Dispose method takes care of closing and deleting the WebResponse and StreamReader variables for you. And C # introduced "var" back in .NET 3.0, you might want to start hugging it, assuming you're using 3.0 or a newer structure. If you want to see how it will look, look below.
Make sure you have these operations:
using System; using System.IO; using System.Net;
Then put these two lines in the static constructor of your form or object, I assume that you are using the form right now:
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls | SecurityProtocolType.Ssl3;
Then your two methods will look like this:
private void button4_Click(object sender, EventArgs e) { try { for (var i = 0; i < listBox2.Items.Count; i++) { var response = Code(listBox2.Items[i].ToString() + "\'"); if (response.ToLower().Contains("mysql")) { Console.WriteLine("positive " + listBox2.Items[i].ToString()); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } } public static string Code(string url) { var webRequest = (HttpWebRequest)WebRequest.Create(url); webRequest.MaximumAutomaticRedirections = 4; webRequest.MaximumResponseHeadersLength = 4; webRequest.UserAgent = "Mozilla/5.0 (Taco2) Gecko/20100101"; webRequest.Credentials = CredentialCache.DefaultCredentials; webRequest.Method = "GET"; using (var webResponse = webRequest.GetResponse()) { using (var sr = new StreamReader(webResponse.GetResponseStream(), System.Text.Encoding.UTF8)) { return sr.ReadToEnd(); } } }
Happy coding! Feel free to ask any questions in the comments below.