How do I read RSS feed through a proxy using RSS.NET? - c#

Trying to use RSS.NET. Example on the site is: (C#)
string url = "http://sourceforge.net/export/rss2_sfnews.php?feed";
RssFeed feed = RssFeed.Read(url);
RssChannel channel = (RssChannel)feed.Channels[0];
listBox.DataSource = channel.Items;
However, this fails because I need to access the feed through a proxy. How do I do this?
An overload for RssFeed.Read() takes HttpWebRequest. I think this may be the way of setting this up, but I haven't used this before. Help! :)

You can indeed use the HttpWebRequest overload of the RssFeed.Read() function. The following should work
string url = "http://sourceforge.net/export/rss2_sfnews.php?feed";
string proxyUrl = "http://proxy.example.com:80/";
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(url);
WebProxy proxy = new WebProxy(proxyUrl,true);
webReq.Proxy = proxy;
RssFeed feed = RssFeed.Read(webReq);
If you need a username and password for the proxy there is a more detailed example here.

There is an overload of the RssFeed.Read() method that accepts an HttpWebRequest. You can set the proxy on the HttpWebRequest and read it that way. This sets the proxy for the RSS feed in particular. You would need to do this for each feed you read in.
You can set the default proxy using System.Net.WebRequest.DefaultWebProxy, prior to calling RssFeed.Read(String). Do this just once; it will apply to all Rss feeds you read, as well as all other http communicatious going out from your app.

Related

Is there any way to hide/override real IP while using anonymous or transparent proxy?

Is there any way to hide/override real IP while using anonymous or transparent proxy?
I want to send empty in HTTP_X_FORWARDED_FOR. I am using C# Winform. Below is the code snippet.
WebClient wc = new WebClient();
//wc.Headers["HTTP_X_FORWARDED_FOR"] = "0.0.0.0"; --Not working
wc.Proxy = new WebProxy(ipproxy, port);
string t = wc.DownloadString("https://www.leaky.org/ip_tester.pl");
The goal is to send completely anonymous request. The proxies I am using is not brought from any website, they are collected from random sites. It would be great if someone also mention any good site of working proxies.
Thanks
Yes. You can use ProxySharp to generate/get proxy servers to use for your request.
https://github.com/m-henderson/ProxySharp
After you install the ProxySharp nuget package, you can get a random anonymous proxy to use with your request. Like this:
WebClient wc = new WebClient();
var proxyServer = Proxy.GetSingleProxy();
wc.Proxy = new WebProxy(proxyServer);
string t = wc.DownloadString("https://www.leaky.org/ip_tester.pl");
It also has different methods for getting, renewing, and popping proxies from the queue that it generates.
Yes. I built ProxySharp to do exactly what you are trying to do.
ProxySharp has a method that will get you a random anonymous proxy to use with your web request. Check out the repo for more info https://github.com/m-henderson/ProxySharp
The X-Forwarded-For header is generally added by the proxy server, not the client. If you put something there, the proxy server will overwrite or append to it.

How to create an otrs ticket using a soap request

The lack of documentation on this subject coupled with the fact that I'm struggling with a learning curve on all fronts and making me really confused about where to start. I need to get this done using C# if possible. I apologize for the vagueness of this question, but I'm really lost. I would love links to comprehensive guides/references.
In my efforts to get this done, I've run into the following problems/questions:
I've created a web service using the otrs gui, with the operation CreateTicket, but requests via C# to my chosen namespace are returning 404 (not found). When I try to add a service reference or web reference with that namespace, I get the same error. However, when I plug that namespace into my browser as the url, it displays "customer.pl".
Can I send a soap request without adding the web service as a service reference in visual studio? Given the previous problem I'm having I can't do it that way. Would I just build the soap request string and write it to the web request's data stream with http://domain/rpc.pl as the uri?
If the answer to the previous question is yes... When trying the below code segment I get an internal server error (500) on the last line. However the header looks like a SOAP header which confuses me because I wouldn't have thought it got that far.
var document = new StringBuilder();
document.Append("<UserLogin>some user login</UserLogin>");
document.Append("<Password>some password</Password> ");
document.Append("<Ticket>");
document.Append("<Title>some title</Title> ");
document.Append("<CustomerUser>some customer user login</CustomerUser>");
document.Append("<Queue>some queue</Queue>");
document.Append("<State>some state</State>");
document.Append("<Priority>some priority</Priority>");
document.Append("</Ticket>");
document.Append("<Article>");
document.Append("<Subject>some subject</Subject>");
document.Append("<Body>some body</Body>");
document.Append("<ContentType>text/plain; charset=utf8</ContentType>");
document.Append("</Article>");
//var uri = new Uri("http://domain/injest");
var uri = new Uri("http://domain/rpc.pl");
var httpWebReq = (HttpWebRequest)WebRequest.Create(uri);
var bytePostData = Encoding.UTF8.GetBytes(document.ToString());
httpWebReq.Timeout = 5 * 1000;
httpWebReq.Method = "POST";
httpWebReq.ContentLength = bytePostData.Length;
httpWebReq.ContentType = "text/xml;charset=utf-8";
//httpWebReq.TransferEncoding=
//httpWebReq.ContentType = "application/xml";
//httpWebReq.Accept = "application/xml";
var dataStream = httpWebReq.GetRequestStream();
dataStream.Write(bytePostData, 0, bytePostData.Length);
dataStream.Close();
var httpWebResponse = (HttpWebResponse)httpWebReq.GetResponse();
Even if all you can offer is where to start, it would help me to know how to proceed, as I'm stumped.
You're using the rpc.pl endpoint which is part of the 'old' RPC-style interface.
You mention you added the web service via the GUI which means you're using the 'new' Generic Interface, which is indeed much easier from .Net.
The address of the endpoint is /otrs/nph-genericinterface.pl/Webservice/GenericTicketConnector or whatever you have called the web service in the admin section.

(403) Forbidden upon WebRequest

I'm trying to create a general whereabouts locator for my chat program. It currently shows IP, Username and I'm trying to add Location. I'm attempting to use this piece of code:
var location = "";
List<string> HTML_code = new List<string>();
WebRequest request = WebRequest.Create("http://www.maxmind.com/app/locate_demo_ip?ips=" + IP);
using (WebResponse response = request.GetResponse())
using (StreamReader stream = new StreamReader(response.GetResponseStream()))
{
string line;
while ((line = stream.ReadLine()) != null)
{
HTML_code.Add(line);
}
}
location = (HTML_code[296].Replace("<td><font size=\"-1\">", "")).Replace("</font></td>", "");
return location;
This, however returns an exception about WebResponse:
The remote server returned an error: (403)
Forbidden.(System.Net.WebResponse GetResponse())
Why am I getting this? And how can I prevent it?
You must have a license key in order to use this service, as written here:
All of the services take the same parameters as inputs. The only difference between them is the URI they use and the data they return. The two parameters that each service takes are the IP address to look up and your MaxMind license key.
Once you get such a key, you have to add it to the URL in addition to the IP address.
I could not find the documentation of that particular REST API call, but it is clear from the company's website that this service is not free (at least not without a license key). This is a classic approach (you accompany each request you make to the API with your app/license key), for example both Twitter and Facebook have it.
Take a look at this link, where they give a code example of how to use their GeoIP service from C#. Also, consider taking a look at their free databases.

URI Update Request

From my C# console application, I want to issue an Uri update request. Like the following:
http://username:password#dynupdate.no-ip.com/nic/update?hostname=mytest.testdomain.com&myip=1.2.3.4
I have tried the following:
string url = "http://username:password#dynupdate.no-ip.com/nic/update? hostname=mytest.testdomain.com&myip=1.2.3.4";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Timeout = 5000;
But, I am getting, Invalid URI: The format of the URI could not be determined. error.
Any idea, where I went wrong? I type the full url as shown above into a web browser and it works as expected but through the C# application, it throws an exception.
Is there any other way to implement this?
You need to create and add some credentials to the request and then access the URI without passing in the username/password.
For more information : How to: Request Data Using the WebRequest Class (Specifically the section regarding credentials)
For example;
var uri = new Uri("http://somesite.com/something");
var request = WebRequest.Create(uri) as HttpWebRequest;
request.Credentials = new NetworkCredential("myUserName","myPassword");
request.PreAuthenticate = true;
Just have look at this web page. Is this what you are referring to?
http://www.no-ip.com/integrate/request/
I think you need to use the url as
http://dynupdate.no-ip.com/nic/update
and then send the credentials as mentioned by ChrisBint. And you need to set the preference to base64 ...if there is a provision for that
+ some headers like UserAgent as mentioned in the article.
Encode the URL argument, check the below example
string url = "http://www.stackoverflow.com?question=" + HttpUtility.UrlEncode("a sentence with spaces");
WebRequest r = WebRequest.Create(url);

Issues retrieving facebook social plugin comments for page, C# HttpWebRequest class

I'm hoping I've done something knuckle-headed here and there is an easy answer. I'm simply trying to retrieve the list of comments for a page on my site. I use the social plug-in and then retrieve the comment id via the edge event. Server side I send the page id back and do a simple request using a HttpWebRequest. Worked well back in October, but now I get an 'internal error' response from FB. I can use the same url string put it into a browser and get the comments back in the browser in json.
StringBuilder url = new StringBuilder();
url.Append("https://graph.facebook.com/comments/?ids=" + comment.page);
string requestString = url.ToString();
HttpWebRequest request = WebRequest.Create(requestString) as HttpWebRequest;
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
Ideas? Thanks much in advance.
Since you're using the Facebook C# SDK (per your tag), try:
var url = "{your url}";
var api = new Facebook.FacebookClient(appId,appSec);
dynamic commentsObj = api.Get("/comments/?ids=" + url);
dynamic arrayOfComments = commentsObj[url].data

Categories