Restsharp: Returns 0 content with error "unable to read data from the transport connection" - mono

Background: Console app built in .Net 4.6.2
Dll: Restsharp 106.15.0.0
Mono: Mono JIT compiler version 6.12.0.122
API Endpoint: http server (not https)
At first I thought I was going mad as all was working okay on windows but when I run my console app on Debian (v9), it will constantly fail with the error: unable to read data from the transport connection. I've narrowed it down to restsharp and not a api/server issue.
When I run a debugger in parallel (HTTP Debugger) I can see the request go out from my console app on Debian and I can also see the endpoint return a result with content! This content does not come into restsharp and so restsharp gives me a content-length of 0 and an error message of:
unable to read data from the transport connection: An existing connection was forcibly closed by the remote host
Any ideas please?
Code to trigger restsharp:
Dim myUri As New Uri(url)
Dim client = New RestSharp.RestClient(myUri)
Dim request = New RestRequest With {.Method = Method.GET}
request.AddHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9")
request.AddHeader("Connection", "keep-alive")
Dim response As RestResponse = client.Execute(request)
Dim strResponse as String = response.Content)
(I've also tried without sending the headers - makes no difference, same error message)
Thanks

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);

An unexpected error occurred on a send. TLS1.1 connection Error

We have some old VB code on a server which is compiled and is making a web service call. The provider recently updated from TLS1.1 to TLS1.2 and that's when the code stopped working and we started getting the error message
Underlying connection was closed: an unexpected error occurred on a send
I am not very familiar with VB. Are there any changes we can make on the Windows Server so that the compiled code makes a connection via TLS1.2?
It took some time, but I've added the stack trace. I've edited it a bit for privacy:
Here is the error message:
The underlying connection was closed: An unexpected error occurred on a send.
Trace:
at System.Web.Services.Protocols.WebClientProtocol.GetWebResponse(WebRequest request)
at System.Web.Services.Protocols.HttpWebClientProtocol.GetWebResponse(WebRequest request)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at (...............).BeginSession(String Profile) in C:\Users...\Desktop.............................vb:line 146
at (................)RetrieveData(Int32 queueNumber) in C:\Users(..................................).vb:line 475
at (.................) in C:\Users(...................................)vb:line 121
Here's a part of the code where a webservice connection is made (line 146 in the stack above):
<System.Web.Services.Protocols.SoapDocumentMethodAttribute("......BeginSession", RequestNamespace:="........com", ResponseNamespace:=".............com", Use:=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle:=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)> _
Public Function BeginSession(ByVal Profile As String) As String
Dim results() As Object = Me.Invoke("BeginSession", New Object() {Profile})
Return CType(results(0), String)
End Function
Add this just before the request:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
ServicePointManager.Expect100Continue = True
I think it should work then.
Worked for me, when I had an error, though a bit different one.
My issue was resolved.The steps I took was to upgrade the project by opening it in the latest version of Visual Studio (2017). I had a few errors upgrading mostly related to the solution file being read-only. I then changed the target framework of the project to 4.6.1.
After doing these changes and rebuilding the solution, the app seems to be working.

SSL connection via Domino managed bean to payment gateway fails with 'handshake_failure'

I have a Java agent that connects to a payment gateway to validate a CC transaction.
Everything seems to work fine when the Java logic is run on my IBM Notes client (9.0.1FP10IF3).
I am now migrating the logic to a managed bean on my Domino server (9.0.1FP6).
Whenever the connection is made through the bean, I observe the following error on the server console...
HTTP JVM: javax.net.ssl.SSLHandshakeException: Received fatal alert:
handshake_failure
I am certain it's because the payment gateway with which I am attempting to communicate has recently upgraded to enforce mandatory TLS 1.2 communications.
However, I'm not sure how to enforce those communications on the Domino server side?
I have set the recommended NOTES.INI variables...
DISABLE_SSLV3=1
SSL_DISABLE_TLS_10=1
... and set the 'SSLCipherSpec', but nothing is working.
Here is an excerpt from the logic I'm using to test everything out.
The 'DataOutputStream' line is what triggers the error...
URL url = new URL("https://host/endpoint");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setAllowUserInteraction(false);
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setUseCaches(false);
connection.setRequestProperty("Content-type", "text/xml");
connection.setRequestProperty("Content-length", Integer.toString(postContent.length()));
DataOutputStream out = new DataOutputStream(connection.getOutputStream());
out.writeBytes(postContent);
out.flush();
out.close();
connection.disconnect();
Any advice/assistance would be most appreciated!
As Per answered, this document allowed me to resolve the issue straight away...
www-01.ibm.com/support/docview.wss?uid=swg21985289

Problems with REST HTTPS request on WinCE

I'm porting a vb.net HTTPS client application on WinCE60 CF35: bsically it needs to send HTTPS REST requests to a server.
I started development on a Win10 desktop and there I have no problems (VS2015 - NET35).
When I run on WinCE I receive an exception when I send the webrequest: the system says that it does not have the error message, but I see the status = 10 = SecureChannelFailure.
The code is the following:
Private Function SendGetRequest(cmd As String) As Boolean
Dim request As WebRequest = WebRequest.Create(m_baseUrl + cmd)
request.Method = "GET"
request.Timeout = m_timeout
request.Headers.Add("Authorization", "Basic " + m_authInfo)
'
Dim dataStream As Stream
'
Try
Dim response As WebResponse = request.GetResponse()
m_statusCode = CType(response, HttpWebResponse).StatusCode
dataStream = response.GetResponseStream()
...
On the server side I don't receive anything. So, I tryed to sniff using Wireshark and I see the following:
In my understanding the client (.113) sends a RESET, but I don't know why ..
PS: if I build a HTTP request I receive response.
Multiple potential issues here:
Based on the error message, the most likely problem: The CE device may be missing a root certificate, or the root certificate may be expired or revoked, and therefore Windows CE is unable to verify the server certificate. If your CE device has a UI, open the Certificates applet in the Control Panel to verify that the required root certificate is installed and valid
.NET CF does not support SHA-2 based certificates (see answers here). Mentioning this because it's the next problem you are likely to run into, once the root cert is in place
Windows CE often sends RST to close TCP connections. Not pretty, but probably unrelated to the HTTPS problem you're seeing (as far as I understand the rationale is this is faster than having both sides send FIN/ACK)

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();