'Unable to connect to the remote server' when connected to corporate intranet - httpwebrequest

var request = (HttpWebRequest)WebRequest.Create("http://www.bbc.co.uk");
string stream;
using (StreamReader reader = new StreamReader(request.GetResponse().GetResponseStream(), Encoding.Default))
{
stream = reader.ReadToEnd();
}
If I'm connected to a corporate intranet I get "Unable to connect to the remote server". When I'm not connected it connects fine. Why might this be?
(The intranet is not the BBC's. That's just a random URL I picked.)

I looked up one of the proxies that IE is using and used that. It worked!

Related

Selenium iOS Driver behind Proxy

We are trying to run some automated tests for our Xamarin based iOS app using the Selenium IOSDriver within Visual Studio for Mac.
The error we are getting when we run them is (I've sanitised to remove the URL we are actually trying to send the request to).
A exception with a null response was thrown sending an HTTP request to the remote WebDriver server for URL https://<Test Host URL>. The status of the exception was NameResolutionFailure, and the message was: nodename nor servname provided, or not known nodename nor servname provided, or not known
Because our machines are behind a proxy we often see DNS errors like this when the code sending the request is unaware of the proxy.
We've tried various approached to setting the proxy, such as HttpClient.DefaultProxy and OpenQA.Selenium.Proxy but the error still persists.
Are there any other ways to tell Selenium that it is operating behind a proxy?
For anyone else struggling with this the answer seemed to be using a 'HttpCommandExecutor'
var uri = new Uri("https://hub.browserstack.com/wd/hub/");
var commandExecutor = new HttpCommandExecutor(uri, TimeSpan.FromSeconds(30))
{
Proxy = new WebProxy
{
Address = new Uri("http://your.proxy")
}
};
driver = new IOSDriver<IOSElement>(commandExecutor, options);

PayPal works fine on localhost, but fails while works on aws server

I have integrated paypal to my MVC4 application. PayPal dll version 1.5.0.0, NewtonJson dll version 6.0.0.0
At first i got exception at localhost while getting access token
Dictionary<string, string> sdkConfig = new Dictionary<string, string>();
sdkConfig.Add("mode", "sandbox");
string accessToken = new PayPal.Api.OAuthTokenCredential("MyClientId", "MySecretId", sdkConfig).GetAccessToken();
Exception was
Invalid HTTP response: The request was aborted: Could not create SSL/TLS secure channel.
From stackoverflow I got a fix
System.Net.ServicePointManager.Expect100Continue = true;
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
System.Net.ServicePointManager.DefaultConnectionLimit = 9999;
Its currently working fine on my localhost, but getting exception when uploaded and run on AWS windows instance.
Retried 3 times.... Exception in PayPal.HttpConnection.Execute(). Check log for more details.
Can somebody help me on this ?
UPDATE
I have checked with uploading the same code in mochahost server. Its working perfectly there too
My EC2 instance is Windows Server 2008 DataCenter, 32 bit with IIS7
Make sure TCP443 is open on any elastic load balancer (ELB) you are using and in the security group assigned to the EC2 instance. In the OS make sure TCP443 is allowed with Windows Advanced Firewall.

FTP 425 Can't open data connection behind IIS

I need to write an application which connects to a FTP server. This FTP server does not allows passive mode connections. I can connect to the FTP server using Filezilla.
I have developed a C# WCF service which connects to this FTP server, using FTPWebRequest class.
Here are the basic settings of the FTPWebRequest object:
ftpreq.Proxy = null;
ftpreq.KeepAlive = true;
ftpreq.UsePassive = false;
When I run the WCF service from Visual Studio(Ctrl+F5) it connects to the FTP server and downloads required files without any issues
But when I host the service in my local IIS 7.5, it fails to connect to the FTP server with following error:
The remote server returned an error: (425) Can't open data connection.
After some googling on this problem, I tried playing around the firewall settings, but it was of no use. Not sure if it is related to some IIS security issue or something else.
Any help would be highly appreciated
This is my way:
Start\ Control Panel\ Windows Firewall\ Allowed Programs.
Here! Tick check box at your application to allow it through Windows FireWall.
Remember! Tick checkbox "Home/Work (private)" as well as checkbox "Public".
good luck!
here is complex solution
step 1
single ftp (non ftps) using two network channels (port and port ranges).
One (tcp:21) for auth, and second, used as data-channel for data.
When configuring ftp on iis, open 21 port for auth and control channel, then in iis control-panel on "FTP Firewall support" specify port range for data (5000-6000) and external ip of network interface married with ftp-server.
step 2
Finally, open tcp:21 in windows firewall and create custon rule, allowing connection on tcp:5000-6000. Restart system (or just restart services).
thats all.
ps. just remember, that ftp on iis using tcp:21 for control/auth and tcp:5000-6000 for data. tcp:5000-6000 may be changes in iis manager 1st, and opened in windows firewall second.
I commented this settings:
UseBinary, Proxy, KeepAlive, UsePassive
and now works good:
FtpWebRequest reqFTP;
reqFTP = (FtpWebRequest)WebRequest.Create(new Uri(ftpLocation + remoteDir));
//reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential(ftpUser, ftpPassword);
reqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
//reqFTP.Proxy = null;
//reqFTP.KeepAlive = false;
//reqFTP.UsePassive = false;
response = reqFTP.GetResponse();
reader = new StreamReader(response.GetResponseStream());
string line = reader.ReadLine();
This code is from microsoft forum: https://social.msdn.microsoft.com/Forums/en-US/079fb811-3c55-4959-85c4-677e4b20bea3/downloading-all-files-in-directory-ftp-and-c?forum=ncl
Same issue happened to me. So I did the following and it fixed it:
- I rebooted the whole FTP server
- After reboot, I launched Internet Information Services (IIS) 6.0 Manager. The Default FTP Site was stopped. I started it. And that fixed it!

WebRTC setup and related queries

I am trying to setup a peer to peer connection for WebRTC application. I have read the forums and discussion groups which lead me to the point that STUN/TURN servers are required for the same. Here are the details:
I downloaded the open source implementation of the STUN/TURN server from https://code.google.com/p/rfc5766-turn-server/
Installed the server on my local Mac OS X machine and turned on the server on localhost:3478
When I tested the server using the client scripts, I was able to get back the remote address from the server.
However, when I try to hit the server from my JavaScript code while creating a peer to peer connection, it is not hitting the server itself.
Below is the code which I am using :
function createPeerConnection() {
var pc_config = {'iceServers': [{'url':'turn:127.0.0.1:3478', 'credential':'Apple123'}]};
try {
// Create an RTCPeerConnection via the polyfill (adapter.js).
pc = new webkitRTCPeerConnection(pc_config);
pc.onicecandidate = gotLocalCandidate;
trace("Created RTCPeerConnnection with config:\n" + " \"" +JSON.stringify(pc_config) + "\".");
} catch (e) {
trace("Failed to create PeerConnection, exception: " + e.message);
alert("Cannot create RTCPeerConnection object; WebRTC is not supported by this browser.");
return;
}
pc.onconnecting = onSessionConnecting;
pc.onopen = onSessionOpened;
pc.onaddstream = onRemoteStreamAdded;
pc.onremovestream = onRemoteStreamRemoved;
}
Appreciate any guidance in this matter as I am completely stuck at this point.
One more question: How to setup a peer to peer connection for WebRTC application where both peer A and B are present on an internal network? Is STUN/TURN servers required then?
First, TURN servers are something that are used only if failing to setup an p2p connection directly. About 86% of all calls can be made without relaying via a TURN server (according to this slide, which I by the way recomend to get a better understanding of TURN (from slide 44)).
TURN server should be outside your network since the purpose of it is to relay the stream when not possible to do so in other way.
I would recomend you to start with the case where both A and B are on the same network. Then you do not need to worry about using STUN/TURN. It's enough complicated as it is.

error writing file on remote server in WCF

I'm creating a WCF (C#, VS2010) for my silverlight app, I'm trying to create a file on my remote server (where WCF exists), but I get an unknown error, I just get "Server not found" error in WCF function complete exception message, I use following codes to create a file on my remote server (I use a VDS, so I think I don't have permission problems, I use remote desktop on my server)
using (StreamWriter outfile =
new StreamWriter("mytest.htm"))
{
outfile.Write(body);
}
what is going wrong here? is it possible that I have permission problems? I run my WCF on local system and it creates file successfully, but there is no luck when it is uploaded to remote server
should I use Server.MapPath for giving address of my file?
Please use this:
System.Net.FileWebRequest request = (System.Net.FileWebRequest)System.Net.FileWebRequest.CreateDefault(new Uri("\\\\remotelocation\\MyText.txt"));
request.Method = "POST";
Stream requestStream = request.GetRequestStream();
byte [] fileContents = Encoding.UTF8.GetBytes("test_content");
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();