I am trying to download response from this url
http://www.youtube.com/get_video_info?html5=1&video_id=sFwcLC5HC9I
The file it returns can be downloaded from browser, but when I try to save it with c# webclient I get only error message.
errorcode=180&status=fail&reason=HTTP+is+not+supported.
Is there any other way to download file from the API without using HTTP?
What have I tried (a is instance of WebClient):
byte[] policko = a.DownloadData("http://www.youtube.com/get_video_info?html5=1&video_id=sFwcLC5HC9I");
a.DownloadFile("http://www.youtube.com/get_video_info?html5=1&video_id=sFwcLC5HC9I", "filename");
a.DownloadString("http://www.youtube.com/get_video_info?html5=1&video_id=sFwcLC5HC9I");
The response you got indicates that HTTP is not supported for this API call. The next natural choice is HTTPS.
https://www.youtube.com/get_video_info?html5=1&video_id=sFwcLC5HC9I
Related
I am trying out the one drive graph api to upload folder to my one drive folder.
Using the regular upload works fine.
I'm also testing the resumable upload, which is used for large files. But this is where I'm getting a strange response.
I'm following this link for how to do it: https://learn.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_createuploadsession.
First i get a create an upload session using "https://graph.microsoft.com/v1.0/me/drive/items/xxxxxxxxxx:/filename.txt:/createUploadSession".
This gives me back an uploadUrl value, something like "https://api.onedrive.com/rup/xxxxxxxxxxxxx"
I then make a PUT request to that URL with the correct headers.
The response I receive is a 400 (bad request) with the following text (including the HTML):
<h2>Our services aren't available right now</h2><p>We're working to restore all services as soon as possible. Please check back soon.</p>Ref A: 235A863C95DC45BE98688D905A7DB3C1 Ref B: BUH01EDGE0107 Ref C: 2018-08-28T18:56:52Z
I have been getting this for 3 days now and I can't seem to get hold of any support from Microsoft. According to this website, everything is running: https://portal.office.com/servicestatus
Does anyone know why I'm getting this error?
I found the cause for the error.
I received the error because I provided the authentication token in the header.
For small file uploads it is required, but for large file uploads it is not required.
I was using the same code for PUT, POST and GET requests, where I only pass in the URL and HTTP Content and i would always add the auth headers. But for large file uploads it is not required.
But still a very strange error response to receive for adding unrequired headers.
I want to download a 68kb zip file using webclient and I have the error:
C# System.Net.WebException: 'Too many automatic redirections were attempted.'
About this post is a duplicated post:
The solution explained in: Why i'm getting exception: Too many automatic redirections were attempted on webclient?
Don't work to make my code below works and download the zip file.
How Can I edit to explain better ?
My code:
var url_from = "http://www1.caixa.gov.br/listaweb/Lista_imoveis_RJ.zip";
var _to = #"F:\folder\file.zip";
using (var client = new WebClient())
{
client.DownloadFile(url_from, _to);
}
I tried Async ways too but it was generated empty zip file.
Like this: How do I download zip file in C#?
and this: How can I download a ZIP file from a URL using C#?
This is caused by a bad server implementation. If you use Fiddler, you'll see that the server redirects both HTTPS and HTTP connections to the same HTTP url, adding a security=true cookie.
Calling over HTTP is particulary funny :
The first HTTP redirects to an HTTPS URL
The HTTPS redirects back to the original HTTP with the security=true cookie
If the cookie isn't there, the loop starts again
This means that :
There's no security. Anything can intercept that call and alter or replace the contents of the file. Hope you don't try to download this file over WiFi!
The server will cause an infinite redirection loop unless you store the cookie or add it yourself.
WebClient can't store cookies. It's an obsolete class created back when downloading pages and files was all that's needed. All of its functionality and much more is provided by the HttpClient class.
In this case though, you can add the cookie as a header yourself and avoid the redirections, and still download the file over HTTPS
WebClient is an obsolete class. It was created for simple file and page requests and
var url_from = "https://www1.caixa.gov.br/listaweb/Lista_imoveis_RJ.zip";
using (var client = new System.Net.WebClient())
{
client.Headers.Add(System.Net.HttpRequestHeader.Cookie, "security=true");
client.DownloadFile(url_from, _to);
}
This will result in a single call and download the file over HTTP
I'm trying to get a csv file from the following uri using C# WebClient.
var copUri ="http://obieebr.banrep.gov.co/analytics/saw.dll?Go&Path=%2fshared%2fSeries%20Estad%c3%adsticas_T%2f1.%20IBR%2f1.1.IBR_CSV_XML_ultimos_datos&download_type=csv&NQUser=publico&NQPassword=publico"
var client = new WebClient();
var content = client.DownloadString(copUri);
When I try it in my browser I get the csv file, but the above code is returning the authentication html file instead. How do I get past this html response to get the csv file?
You have pass Authorization credentials with uri.
Server rejected your request due to un-authenticate activity.
The problem was beyond the cookie awareness - the csv was compiled with javascript in the browser. Solved by using Casperjs to render the obfuscating javascript and then getting the data from the underlying instance.
I am trying to enable users on a web application to download HTML strings of any URLs using ASP.NET MVC. I know that it would be very easy to download a page using the following code:
using (WebClient client = new WebClient ())
{
string code= client.DownloadString(URL);
//...
}
Now the question is whether I need to check the request for any possible or potential attacks or malwares ot etc?
P.S: How would I know what file type I am getting? If it is let's say an image file, the response (somewhere I don't know) should have the content-type. Where is it?
You can send a md5 hash of a file to Virus Total and see if a file is a known virus.
I am sending a file as part of the FormData from AngularJs to .NET Web API as follows:
AngularJS:
var cabinetFormData = new FormData();
cabinetFormData.append('file', file);
Sending the above FormData as a parameter in the service call to .Net WebAPI
.NET:
var httpRequest = HttpContext.Current.Request;
var fileRequest = httpRequest.Files[0];
While receiving the request on the server side, the fileRequest.FileName is always showing up as "blob" for any image files. Rest of the content is showing up fine. Getting proper File names for other format's like .pdf and .xml. I have checked the input, and it's sending all the formData.
What am i doing wrong ?
I would post this as a comment, but I don't have the rep yet..
If you're using Firefox when you see this issue, these links might help you out:
Uploaded file comes in as blob if not on localhost? asp.net mvc4 using IIS express
https://groups.google.com/forum/#!topic/jquery-fileupload/RjfHLX2_EeM
:)