将base64中的空格去掉
代码:
public ActionResult body_seg(string base64) { string token = getAccessToken(); logo: string host = "https://aip.baidubce.com/rest/2.0/image-classify/v1/body_seg?access_token=" + token; Encoding encoding = Encoding.UTF8; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(host); request.Method = "post"; request.KeepAlive = true; // 图片的base64编码 //string base64 = getFileBase64("[本地图片文件]"); String str = "image=" + HttpUtility.UrlEncode(base64.Replace(" ", "+").Replace("=", "A")); // String str = "image=" + HttpUtility.UrlEncode(base64); byte[] buffer = encoding.GetBytes(str); request.ContentLength = buffer.Length; request.GetRequestStream().Write(buffer, 0, buffer.Length); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8); //"log_id": 2451426617428943180, string result = reader.ReadToEnd(); var obj = result.ToJson(); result = obj.ToString(); System.Diagnostics.Debug.WriteLine(result); var JResult = result.ToJObject(); //Console.WriteLine("人像分割:"); //Console.WriteLine(result); string str_result = ""; try { str_result = JResult["foreground"].ToString(); return Content(new ResParameter { code = ResponseCode.success, info = "1", data = str_result }.ToJson()); } catch (Exception ex) { str_result = JResult["error_code"].ToString(); return Content(new ResParameter { code = ResponseCode.fail, info = "3", data = str_result }.ToJson()); } //return result; }