Reading this site Rss - rss

I'm trying read this site's Rss using following code:
WebRequest request = WebRequest.Create("http://alef.ir/rssew.skj1zjyss1rhx2k4m..9ji9b7.jbgjzqg.xml")
Stream stream = request.GetResponse().GetResponseStream();
XmlDocument rss = new XmlDocument();
rss.Load(stream);
XmlNodeList items = rss.SelectNodes("rss/channel/item");
.
.
.
But VS shows this problem:
The remote server returned an error: (403) Forbidden.

It may have been temporary. Any time you have a problem getting a remote document programmatically you should go to the url in the browser and check if you can get it outside VS. I visited the url just now and had no problem getting the feed in my browser. You should not have problems to get that feed with VS now.

Related

How to download file by code sent with Response.TransmitFile?

OK, after reading some of the posts here and trying many different ways to download file sent with TransmitFile command Ive decided to write question anyway hoping someone will help me.
I have 2 pages master.aspx and client.aspx. With the master page, I am downloading and uploading files to multiple websites and that way keeping them in sync. Client pages are on those servers and they are handling downloading and uploading content on the particular site itself.
Now to download (send page) from a client page I am using this code (excerpt):
Response.TransmitFile(sPath + sFileName)
Response.Flush() ' Sends all currently buffered output To the client.
Response.SuppressContent = True ' Gets Or sets a value indicating whether To send HTTP content To the client.
ApplicationInstance.CompleteRequest() ' Causes ASP.NET To bypass all events And filtering In the HTTP pipeline chain Of execution And directly execute the EndRequest Event.
Response.End()
to download that content I am using this:
Using client As WebClient = New WebClient()
SourcePath = rootDir + "UploadedFiles\"
If Directory.Exists(SourcePath) = False Then
Directory.CreateDirectory(SourcePath)
End If
client.DownloadFile(lblURL.Text + "?action=download&Path=" + Uri.EscapeDataString(SourcePath) + "&FileName=" + Uri.EscapeDataString(InputFileName) + "&AdminCode=" + Uri.EscapeDataString(cAdminCode), SourcePath + InputFileName)
End Using
But all that I am getting is the HTML content of client.aspx page, it seems that client.DownloadFile can't figure out that I want to download a file not that page itself. How to make client.DownloadFile to download file sent with TransmitFile?
Thanks,
Dejan
UPDATE:
I have found an issue with my path variables, because Ive changed to DownloadFile that has two parameters (second target file path), I was wrongly sending the target file as a parameter to the remote procedure and that's why didn't get the file.

Exception getting while migration of alfresco content, Too many open files

I am getting this error while migrating content from one alfresco repository to other.
And I am getting this error on live production server logs.
And also Server is getting down while migration is running.
Can anyone please help me to resolve this issue or any suggestion is there to avoid this issue.
Any help or comments will be appreciated.
Thanks in Advance.
I have written below code snippet
ContentStream contentStream = new ContentStreamImpl("content." + FilenameUtils.getExtension(fileName),
BigInteger.valueOf(fileName.length()), new MimetypesFileTypeMap().getContentType(newfile), doc.getContentStream().getStream());
I have 2 repositorys,Using above code I am reading content stream from source and creating new file in target repository and adding the content stream. But I didn't found any way to to close the content stream.
Please find below error log for more details.
java.net.SocketException: Too many open files
at java.net.PlainSocketImpl.socketAccept(Native Method)
If you are using the DotCMIS method GetContentStream on the client side, make sure you always close the stream - even if you are not reading it. Otherwise, the socket to the server stays open. Depending on your application the client and/or the server can run out of sockets.
Closing the stream works like this:
IContentStream contentStream = document.GetContentStream();
Stream stream = contentStream.Stream;
... do something with the stream ...
stream.Close();

trying to upload image to Azure but getting 404

I'm trying to upload an image from Server to Azure:
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(GLOBAL_AZURE.AZURE_STORAGE_CONNECTION_STRING);
CloudBlobContainer container = storageAccount.CreateCloudBlobClient().GetContainerReference("my-container");
CloudBlockBlob blockBlob = container.GetBlockBlobReference("my-img.jpg");
using (FileStream img = File.Open("d:\...\my-img.jpg",FileMode.Open))
{
blockBlob.UploadFromStream(img);
}
Everything works fine until UploadFromStream throws:
"The remote server returned an error: (404) Not Found."
my-container was created on the Portal and was defined "Public Blob".
Any ideas what might be the problem?
This is caused if the container does not exist
See this SO question as well getting 404 error when connecting to azure storage account
You can ensure the container exists by calling container.CreateIfNotExists() prior to uploading the blob.
Personally I run this as part of some application start up code rather than on every blob upload.
This article has background
https://azure.microsoft.com/en-gb/documentation/articles/storage-monitoring-diagnosing-troubleshooting/#the-client-is-receiving-404-messages
In the scenario where a client is attempting to insert an object, it
may not be immediately obvious why this results in an HTTP 404 (Not
found) response given that the client is creating a new object.
However, if the client is creating a blob it must be able to find the
blob container, if the client is creating a message it must be able to
find a queue, and if the client is adding a row it must be able to
find the table.

Parse XML from an online source

I'm attempting to parse the xml located at view-source:http://www.parkrun.com.au/wp-content/themes/parkrun/xml/geo.xml. This is my first attempt at doing this type of thing so my knowledge is limited. I've parsed plenty of websites but not xml.
I've attempted the following code but keep getting an error:
Dim xdoc As New XmlDocument
xdoc.LoadXml("http://www.parkrun.com.au/wp-content/themes/parkrun/xml/geo.xml")
Error: {"Data at the root level is invalid. Line 1, position 1."}
What I'm attempting to do is parse the xml and then loop through the records to build an array based on each location and state (eg from below it would be ipswichqld, Queensland). For example below ipswichqld belongs to Queensland (r="4" joins with id="4").
Any help on this would be really appreciated, thanks in advance.
Instead of LoadXml() method, you should've used XmlDocument.Load() method to load XML from local or online source file :
Dim xdoc As New XmlDocument
xdoc.Load("http://www.parkrun.com.au/wp-content/themes/parkrun/xml/geo.xml")
Unfortunately, particular website you're trying to load XML from doesn't allow this operation (not even if you open that XML URL from browser). I got this exception when trying above code :
WebException
The remote server returned an error: (403) Forbidden.

Blackberry http connection not working on 3g

hi friends i'm a newbie in blackberry programming and have managed to make a small application... The application downloads an xml file through http and parses it and displays it on the screen... now the problem is that though it works fine on my simulator... the client complains that he's getting an error in connection if he connects it through 3G... do i need to add anything other than the following...
// Build a document based on the XML file.
url = <my clients url file>;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
hc = (HttpConnection)Connector.open(url+";deviceside=true");
hc.setRequestMethod(HttpConnection.GET);
InputStream inputStream = hc.openInputStream();
hc.getFile();
Document document = builder.parse(inputStream);
hc.close();
inputStream.close();
Do i need to add anything to make it download http content through 3G also??
Specifying "deviceside=true" requires the device have the APN correctly configured, or you include APN specification in the URL. Have a look at this video.
You need to be able to detect what sort of connection the device is using as was said above deviceside=true works only for APN. If you want to just test it out try using
;deviceside=false //for mds
;deviceside=false;ConnectionType=mds-public //for bis-b
;interface=wifi //for wifi

Resources