Archive

Archive for April, 2019

Support #HTTP2 in your C# Client code

http2

If you use code such as WebClient to make HTTP requests from C#, then you’re probably using HTTP 1.1. if you want to use HTTP/2 then you need to write some extra code.

First, let’s prove that you’re using HTTP 1.1

WebClient wc = new WebClient();
var check1 = wc.DownloadString(“https://http2.pro/api/v1”);

and the response is

{“http2″:0,”protocol”:”HTTP\/1.1″,”push”:0,”user_agent”:””}

Now, to use HTTP 2, you need to override a setting here;

public class Http2CustomHandler : WinHttpHandler
{
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
{
request.Version = new Version(“2.0”);
return base.SendAsync(request, cancellationToken);
}
}

And we can make a GET request like so;

public static string GetHtmlFromUrl(string Url)
{
var httpClient = new HttpClient(new Http2CustomHandler { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate });
var resTask = httpClient.GetAsync(new Uri(Url));
var response = resTask.Result;
var strTask = response.Content.ReadAsStringAsync();
var strResponse = strTask.Result;
return strResponse;
}

And check again;

var check2 = GetHtmlFromUrl(“https://http2.pro/api/v1&#8221;);

Which yields

{“http2″:1,”protocol”:”HTTP\/2.0″,”push”:0,”user_agent”:””}

Hope this helps!

 

 

 

Categories: Uncategorized

SMTPJS.com now supports #BCC in #Javascript #Email

smtpjs

SMTPJs.com is a Javascript library for sending email from client-side Javascript (not node), it offers plenty of features for sending email, but one was missing until this morning, the ability to send BCC emails. (Blind Carbon-Copy)

It’s used just like the “To” field as follows

 Email.send({
            SecureToken : “…..”,
            To : [“salesguy@gmail.com“, “boss@gmail.com“] ,
            Bcc : [“private_admin@hotmail.com“, “Auditors@private.es“],
If Bcc is sent as an array, it can send to multiple addresses, or can be just a string, if you just want to send to one BCC.
Happy mailing …
Categories: Uncategorized

Temporary failure in name resolution #Fix #Linux #PHP

Firefox-having-DNS-issues-Ubuntu-17.04

If you get this error message in PHP,

php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution

Then you are either calling a domain name that doesn’t exist, or your DNS resolution has failed on your server. Assuming you haven’t mistyped the API url, then you can check for a DNS issue by SSH’ing into your server and trying to ping http://www.google.com and see if you get a response. – If that fails, then you need to fix your resolving DNS servers, and perhaps contact your host company too.

Google offer their own DNS resolving servers for free, and you can use them as follows;

sudo echo nameserver 8.8.8.8 > /etc/resolv.conf
sudo /etc/init.d/httpd restart

Which changes the DNS resolver on your server to Google’s server with IP 8.8.8.8, and then restarts your web server. You may use apache2 here instead of httpd – depending on your flavour of linux.

 

Categories: Uncategorized