public static string Translate(string text) { var www = new Httpdoer("https://api.datamarket.azure.com"); www.Method = HttpRequestMethod.Get; www.Path = "Bing/MicrosoftTranslator/v1/Translate"; www.Query.AddModel(new { Text = $"'{text}'", To = "'zh-CHS'" }); www.Headers["Authorization"] = AUTH_TOKEN; return(GetText(www.GetString())); }
public void 测试自定义ContentType() { var www = new Httpdoer("http://www.baidu.com"); www.Path = "s"; www.Method = HttpRequestMethod.Put; www.Body.ContentType = new HttpContentType("aaabbbccc", null, null, HttpBodyParsers.Stream); www.Body.Wirte(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }); var str = www.GetString(); Trace.WriteLine(www.Response.RequestData.Raw); Assert.IsNull(www.Exception); }
static void Main(string[] args) { var www = new Httpdoer("www.baidu.com"); www.Body.ContentType = HttpContentType.Json; www.Method = HttpRequestMethod.Post; www.Body.Wirte(Encoding.UTF8.GetBytes("{'a':1}")); // www.Body.AddModel(new { a = 1, b = "fdsfdas", c = new { d = true, e = DateTime.Now, f = new[] { 1, 2, 3, 4, 5 } } }); var str = www.GetString(); Console.WriteLine("-----------------------------------"); Console.WriteLine(www.Response.RequestData.Raw); Console.WriteLine("-----------------------------------"); Console.WriteLine(str); }
public void 基本功能测试() { var www = new Httpdoer("https://api.datamarket.azure.com"); www.Method = HttpRequestMethod.Get; www.Path = "Bing/MicrosoftTranslator/v1/Translate"; www.Query.AddModel(new { Text = "'hello world'", To = "'zh-CHS'" }); www.Headers["Authorization"] = AUTH_TOKEN; var str = www.GetString(); Assert.AreEqual("世界您好", GetText(str)); }
public void 测试头编码() { var model = new { OwnerId = 510789, BrokerKId = 49005, BrokerName = "肖佳", Phone = "15012345600", EarnestMoney = 15200, HouseList = new[] { new { VillageName = "凤凰城", Building = "1幢", HouseId = "12" } } }; var www = new Httpdoer("www.baidu.com"); //www.Timeout = new TimeSpan(0,0,1); www.Headers.KeepAlive = true; www.Cookies.Add(new Uri("http://www.baidu.com"), new Cookie("sessionid", "123456789")); www.Body.AddModel(model); www.Method = HttpRequestMethod.Post; www.Body.ContentType = HttpContentType.Json; www.GetString(); }