WebClient().DownloadString() returning old data [duplicate] - c#

This question already has answers here:
C# WebClient disable cache
(12 answers)
Closed 7 years ago.
I am using this code to get the return string from URL
webClient.Encoding = Encoding.UTF8;
response = webClient.DownloadString("http://somesite.com/code.php");
Console.Write(response);
the code.php looks like this
<?php
$data = file_get_contents('code.txt');
echo $data;
?>
The problem is when I change the contents of the code.txt file, the webClient.DownloadString() method returns the old contents of the code.txt file. When I open the URL http://somesite.com/code.php in a browser it works perfectly fine.
Any solutions will be appreciated!
My question seems to be duplicated but I don't really understand what is said here: C# WebClient disable cache
If anyone could explain and provide some example code it would be great!

Try disabling the cache on the WebClient
webClient.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore);
MSDN Documentation on WebClient Cache

Related

Read data from .Rdata File in C# [duplicate]

This question already has an answer here:
It is possible to read .Rdata file format from C or Fortran?
(1 answer)
Closed 6 years ago.
I have requirement to read data from ".RData" files and process them in C# application. I could not find any API which I can use in C#, I believe there is an API for F# which I don't use as of now because of learning curve in F#.
Could anybody please suggest code or API to read ".Rdata" files?
There's R.NET which would allow you to execute the load function, then get the saved variables from the environment, maybe? My guess is you'll need to run something like
engine.Evaluate("load('/my/data/dir/mydata.RData')");
var data = engine.GetSymbol("myvariablename");

Asp.net Web API cant read file from file path [duplicate]

This question already has answers here:
ASP.NET MVC Website Read File from Disk Problem
(3 answers)
Closed 7 years ago.
I am developing an azure asp.net web api 2 ,and in my api i am trying to read a dataset ,however i couldnt get my dataset.csv path.I connect to ftp server and i found the rout is : ..../site/wwwroot/dataset.csv this ,
I tried this
string path = "/site/wwwroot/dataset.csv";
and also this
string path=Path.Combine(System.Web.HttpRuntime.AppDomainAppPath, "dataset.csv");
however none of them is working i couldnt read the data file , how can i read it ?
Thanks
Try using System.Web.HttpContext.Current.Request.MapPath() instead:
string path=System.Web.HttpContext.Current.Request.MapPath("~\\dataset.csv");
Oh, and a friendly ask: please search StackOverflow before posting questions - this has been asked and answered here

Asp and WebClient: How to get dynamically actual host? [duplicate]

This question already has answers here:
How to get "Host:" header from HttpContext (asp.net)
(4 answers)
Closed 8 years ago.
I want to get datas from an html file on my asp webserver, in Javascript to get actual host we can use the following:
~/mydatas.php
It gives on localhost: "http://localhost/mydatas.php"
I want the same thing but in C# can you help me?
Thanks you.
You could also search in stackoverflow and you will find a lot of answered question which had the same problematic than you. Like this one
Hopes it will help you !
Edit : You can use
HttpContext.Current.Request.Url.AbsoluteUri
It will give you the URL of your web page.
I've already try
HttpContext.Current.Request.Url.Host
which gives on localhost
:\windows\system32\inetsrv\localhost
...

how to read image from url and save it into internal storage for windows 8 with c# [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to use httpwebrequest to pull image from website to local file
Let said, I have a picture a http://abc.com/image/abc.jpg and I would like to download it and save into the own storage in my windows 8 store application (not store into the picture library), so that my application can call and display the image and the image is not seem from picture library.
how to achieve the above task with c# ? code samples? thanks!
Probably better to let the browser cache this as that plumbing is already in place.
If you really want to pull this off, use HttpWebRequest is the class to use and How to use httpwebrequest to pull image from website to local file seems to have a descent answer.

How to Test a Proxy with C#? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
C# Connecting Through Proxy
I've tried doing this for a long time in many different ways but nothing seems to work. Essentially I want to create a proxy checker in C# that checks it by actually going to a page (e.g. http://google.com/ncr) and determines from there if it got there or not.
Is this even possible?
If it is a http proxy
bool OK = false;
try
{
WebClient wc = new WebClient();
wc.Proxy = new WebProxy(Host, Port);
wc.DownloadString("http://google.com/ncr");
OK = true;
}
catch{}

Categories