Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
This is my code. What am i trying to do is connect to webservice and download a file to a specific location.
Code throws an exception. Looks like i should retun some value to service before i download a file (not sure tho).
WebClient webClient = new WebClient();
NetworkCredential netCred=new NetworkCredential();
netCred.UserName="user";
netCred.Password="pass";
netCred.Domain="domain";
webClient.Credentials = netCred;
WebProxy wp = new WebProxy();
wp.Credentials = netCred;
wp.Address = new Uri(#"http://okolje.arso.gov.si/service/prevozniki.zip");
webClient.Proxy = wp;
webClient.DownloadFile("http://okolje.arso.gov.si/service/prevozniki.zip", #"C:\arso\prevozniki.zip");
you need to say what port your proxy is e.g.
webClient.Proxy = new WebProxy("127.0.0.1:8118");
you also have to actually set up this proxy, webclient.proxy just uses it, it doesn't create it
I'm not entirely sure what the rest of your code is doing, but I don't think you need the
wp.Address = new Uri(#"http://okolje.arso.gov.si/service/prevozniki.zip");
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I looking for a code to remove images from FTP but does'nt work
I tried to use this code but not work for me:
Dim FTPRequest As System.Net.FtpWebRequest = DirectCast(System.Net.WebRequest.Create("ftp://myftpname.es/Html/images/" & imagename), System.Net.FtpWebRequest)
FTPRequest.Credentials = New System.Net.NetworkCredential("FTPUsername", "FTPPassword")
FTPRequest.Method = System.Net.WebRequestMethods.Ftp.DeleteFile
FTPRequest.UsePassive = True
FTPRequest.UseBinary = True
FTPRequest.KeepAlive = False
How can I remove images from ftp?
Thanks
this code not remove the image from the ftp
That's because you never actually execute it, you just initialize it. To issue a WebRequest, you need to get its response:
var response = FTPRequest.GetResponse()
Have you tried using the FtpClient class?
Dim client as new System.Net.FtpClient.FtpClient()
client.Credentials = new NetworkCredential("FTPUsername", "FTPPassword")
client.Host = "ftp://myftpname.es"
client.Connect()
client.DeleteFile("Html/images/" & imageName)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a desktop application that has some classes, which I want to serialize and send to a webpage when a user clicks a button in the desktop C# application.
The data is too long for an argument. What I want to achieve here is, how do I post it and open the website on the clients PC with the dynamic changes made by the sent data ?
Need some suggestions or guidance to proceed in the right direction.
You can use HttpClient
For example:
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://myUrl");
var gizmo = new Product() { Name = "Gizmo", Price = 100, Category = "Widget" };
response = await client.PostAsJsonAsync("api/products", gizmo);
if (response.IsSuccessStatusCode)
{
//do something
}
}
One option would be to generate local page with form that contains data and "action=POST" pointing to your site. Than set script that automatically submit this form and as result you'll have data send by browser and browser will continue as if it is normal POST request.
If you don't like HttpClient you can also use WebClient which is a convenience wrapper for your exact scenario.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm working with StreamReader in my Asp.Net mvc application.
I'm having an issue getting the StreamReader to use the root of my application, and not the C:// drive on my machine.
I have the following:
public ActionResult Test()
{
XmlSerializer serializer = new XmlSerializer(typeof(Test));
TextReader textReader;
textReader = new StreamReader("../Content/items.xml");
Test test = (Test)serializer.Deserialize(textReader);
textReader.Close();
return View(test);
}
When you run a web application, the current working directory of the process isn't the directory containing your source code. You might want to look at HttpServerUtility.MapPath or HostingEnvironment.MapPath.
Note that this doesn't really have anything to do with StreamReader - for diagnostic purposes, you'd be better off with something like:
FileInfo file = new FileInfo("../Content/items.xml");
Debug.WriteLine(file.FullName);
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Currently working with Unity, this might a super basic question, but here goes.
I need to call a URL from my app in C#. This is done for analytics purposes, and so I don't want to open a web browser or anything, just call the URL and that's it. I know about Application.OpenURL() to open the browser, but how do I achieve this without opening the browser ?
You may try like this:
var client = new WebClient();
var x = client.DownloadString("http://example.com");
or
HttpWebRequest request = WebRequest.Create("http://example.com") as HttpWebRequest;
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
Stream stream = response.GetResponseStream();
Use the WebClient class in the System.Net namespace.
It's a high level implementation of an HTTP client which is really easy to use.
Has a method called .DownloadString() which does exactly what you want - calls a URL using HTTP GET and returns the response as a string.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a URL, such as http://www.mydomain.com/?param1=asd2¶m2=asd2.
I'd like to create a sort of Frequest object, so than I can easily do somethings like:
Request.Querystring("param1")
without do a further Split and access to the array. Can I?
Your question is not clear. Are you looking something like this?
var uri = new Uri("http://www.mydomain.com/?param1=asd2¶m2=asd2");
var nv = uri.ParseQueryString();
Console.WriteLine(nv["param1"]);
EDIT
It seams one of my referenced libraries implemented this extension Method. Anyway, it can be done as
var uri = new Uri("http://www.mydomain.com/?param1=asd2¶m2=asd2");
var nv = HttpUtility.ParseQueryString(uri.Query);
Console.WriteLine(nv["param1"]);