A Little time ago I opend a thread (link at the bottom).
And I'm happy to say it has been fixed, that is partially.
It still uses the wrong youtube links.
And since youtube keeps updating all examples i could find where broken.
I think this has to do with the "regular" expressions.
Could someone enlighten me on that subject?
And now for the error at hand:
An unhandled exception of type 'System.Net.WebException' occurred in System.dll
Additional information: The remote server returned an error: (403) Forbidden.
At Line 22: wc.DownloadFile(kvp.Value, #"C:\Users\waralot\Downloads\youtube\"+kvp.Key);
The console during compilation is here: pastebin.com/BrgKkAmk
Original project at HackForums: http://www.hackforums.net/showthread.php?tid=2052105
My current version: http://pastebin.com/2iH2vQ2L
Again my first thread can be found here: Converting a Youtube downloader form VB to C#
Seems like Youtube blocks you from accessing the link, this may because you don't set an user-agent for your WebClient.
Try adding this before you try to download the video.
wc.Headers.Add ("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
Code for url cleanup also needs to be changed like so.
//clean up residual tags and encoded strings
link = slink.Replace("url=", "");
link = link.Replace("\\u0026", "&");
link = HttpUtility.UrlDecode(link);
Related
I have a project under source control and I'm using a dynamic view. This project uses sockets. When I run the program I get an exception using this line of code:
var addresses = Dns.GetHostAddresses(Dns.GetHostName());
I get a socket exception with the following information:
Error Code: 11003
Message: "A non-recoverable error occurred during a database lookup"
Socket Error Code: NonRecovery
I don't have this issue running locally or on another windows network share (non-Clearcase). I believe this is a security issue related to sockets and network drives. I have a workaround but would really like to resolve this issue. I'm on Windows 7.
The first workaround would be to use a snapshot view instead of a dynamic one.
That way, you would be directly on the C drive instead of an MVFS mount point.
If you have to use dynamic view, make sure it is being accessed through its full path (no subst, no setview): M:\myview\myVob\...
Finally, it can depend on your exact ClearCase version: with ClearCase 7.x, there was socket error on Windows before: see "Unable to run executable that opens a socket on Microsoft Windows Vista, Windows Server 2008 or Windows 7"
I have done a bit of research on this problem before. I had a look at this question and it didn't help me. Basically I am trying to build a program to help people use a website, and I need to get the recaptcha V2 challenge images from google's recaptcha API. I keep getting a
Specified value has invalid HTTP characters
when attempting to download the stream
try
{
WebClientEx wc = new WebClientEx(cookieJar);
wc.Headers.Add("Referer", recaptchaframe_url);
wc.Headers.Add("UserAgent:", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)");
Stream responsestream = wc.OpenRead("http://www.google.com" + challengeimageurl);
}
catch (Exception ex)
{
MessageBox.Show("This program was unable to download CAPTCHA image" + ex.Message);
}
I was able to get past this error by converting all manually set headers in the webclient to their .NET properties. (eg UserAgernt to HttpRequestHeader.UserAgent. It appears that it's useless to set header names manually.
I am trying to create a simple Windows Phone 8.1 (hence Windows.Networking.Sockets) socket client, and Windows 8 server. Unfortunately I am quite new to this task, so I am having problems understanding the obstacles that appear.
I am using http://msdn.microsoft.com/pl-pl/library/fx6588te(v=vs.110).aspx this code as a server. However when it comes to the Windows Phone 8.1, it turned out that http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202858(v=vs.105).aspx this tutorial won't work, as there is no way to use the following import:
using System.Net.Sockets.
Which is the reason why i switched to the following code:
http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj150599.aspx (which is btw quite sloppy, and full of errors)
So I embedded the Windows Phone 8.1 part of the code into my application, and it seems to connect correctly to the server, and it even sends data to the server, however the app crashes right after the following statement.
"Trying to send data"
And the output is exactly like the following:
A first chance exception of type 'System.ArgumentException' occured in Project.exe
WinRT information: count
Please help me solve the error, as I have vainly spent many hours trying to fix this..
EDIT
Here is the part of code from the mentioned tutorial, that throws the described error
// Now try to receive data from server
try
{
OutputView.Text = "";
StatusText.Text = "Trying to receive data ...";
DataReader reader = new DataReader(clientSocket.InputStream);
// Set inputstream options so that we don't have to know the data size
reader.InputStreamOptions = Partial;
await reader.LoadAsync(reader.UnconsumedBufferLength);
}
I use webclient download to youtube, i have an 100 mb connection but my mp4 download rate 100kb/s :)
WebClient client = New WebClient;
client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 6.1; .NET CLR 1.0.3705;)");
client.Proxy = Null;
client.DownloadFileAsync(New Uri(url.ToString()), directory + file.ToString());
How to fix this problem or where my wrong?
I think youtube block my speed but i tried Internet download manager then very fast down this video.
Thanks for help!
Sorry for my bad English.
Ertim Abon
There's nothing inherently wrong with your code - the "problem" is on the other end. YouTube throttles the connection so that the video is downloaded at about the same speed as it's played. This saves on bandwidth if (when!) people don't watch the entire video. Well-configured video streaming websites will give you a burst at the start and then stream the rest at a lower speed.
The only way around it would be to see if you could make multiple requests to different parts of the video to get the "burst" multiple times, for instance with Range headers. They might not like you doing that though.
There are several questions like this, but my situation seems a bit different. I have extremely simple code:
WebClient client = new WebClient();
client.DownloadFile("http://www.xkcd.com", "xkcd.html");
However, I get the error "No connection could be made because target machine actively refused the connection." However, I also see this problem with connections to any website. It also only appears in .NET applications, all of a sudden, none of them can access the web.
Any ideas?
For the purpose of a sanity check, I like using PowerShell to call api's, so I'd suggest that if you can.
Also, make sure to try that url in IE on the system just to make sure there's nothing weird going on (forced proxy, site is really down, DNS or hosts file is resolving it to something else, etc).
C:\Users\james » $wc = new-object system.net.webclient
C:\Users\james » $wc.DownloadFile("http://www.xkcd.com", "xkcd.html")
C:\Users\james » dir .\xkcd.html
Directory: Microsoft.PowerShell.Core\FileSystem::C:\Users\james
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 8/26/2010 1:08 AM 7454 xkcd.html
The user that your code is running as is relevant. For example the code might work in a console/WinForms app but not in an ASP.NET app.
Try to go to the site using Internet Explorer browser. The problem is the WebClient uses proxy settings from IE. And there are any wrong proxy settings you'll get the message you've got.