c# 微软小冰-虚拟女友聊天
using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Text; using System.Threading.Tasks; namespace TestXiaobingChat { public class HttpHelper { public static string Cookie = Properties.Resources.cookie ; public static string HttpPost(string Url, string postDataStr,bool jsonPost=false ) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url); request.Method = "POST"; // request.ContentType = "application/x-www-form-urlencoded"; //application/json;charset=UTF-8 request.ContentType = "application/x-www-form-urlencoded"; if (jsonPost) { request.ContentType = "application/json"; } byte[] postData = Encoding.UTF8.GetBytes(postDataStr); request.ContentLength = postData.Length; request.Referer = "https://ux-plus-bing.xiaoice.com/BingVirtualGF?authcode=51E6AE30F8FABC23FAF64F73A102BC9F"; // request.CookieContainer = cc; request.Headers.Add("cookie",Cookie); Stream myRequestStream = request.GetRequestStream(); myRequestStream.Write(postData, 0, postData.Length); myRequestStream.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); // response.Cookies = cookie.GetCookies(response.ResponseUri); Stream myResponseStream = response.GetResponseStream(); StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.UTF8); string retString = myStreamReader.ReadToEnd(); myStreamReader.Close(); myResponseStream.Close(); return retString; } public static string HttpGet(string Url) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url); request.Method = "GET"; request.ContentType = "text/html;charset=UTF-8"; request.Headers.Add("cookie", Cookie); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream myResponseStream = response.GetResponseStream(); StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8")); string retString = myStreamReader.ReadToEnd(); myStreamReader.Close(); myResponseStream.Close(); return retString; } } }
private void Button_Click(object sender, RoutedEventArgs e) { HttpHelper.HttpPost("https://ux-plus-bing.xiaoice.com/s_api/game/getresponse?workflow=AIBeingsBingGFChat", Properties.Resources.para ,true ); }
para= {"TraceId":"15ee7bcc2310cefe2ef196df9599f44ad","PartnerName":"bingaibeings","SubPartnerId":"virtualgf","Content":{"Text":"在干嘛","Metadata":{}}}
fffffffffffffffff
test red font.