zoukankan      html  css  js  c++  java
  • 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.
  • 相关阅读:
    UVA 10617 Again Palindrome
    UVA 10154 Weights and Measures
    UVA 10201 Adventures in Moving Part IV
    UVA 10313 Pay the Price
    UVA 10271 Chopsticks
    Restore DB後設置指引 for maximo
    每行SQL語句加go換行
    种服务器角色所拥有的权限
    Framework X support IPV6?
    模擬DeadLock
  • 原文地址:https://www.cnblogs.com/wgscd/p/15433517.html
Copyright © 2011-2022 走看看