C# 通过URL调用接口6666666666666666666666666666666666666 5C

图片说明
怎么调用这个接口
下面是我写的代码

    /// <summary>
    /// 添加图片
    /// </summary>
    /// <param name="fp"></param>
    /// <returns></returns>
    public static int AddPhoto(FacePhoto fp)
    {
        string MethodPath = ipPath + "/face/create";
        Encoding myEncoding = Encoding.GetEncoding("gb2312");  //选择编码字符集
        string data = "pass=admin12345&personId=" + fp.personId + "&faceId=\"\"&imgBase64=data:image/jpg;base64," + fp.imgBase64;
        byte[] bytesToPost = System.Text.Encoding.Default.GetBytes(data); //转换为bytes数据
        string responseResult = String.Empty;
        HttpWebRequest req = (HttpWebRequest)
        HttpWebRequest.Create(MethodPath);   //创建一个httprequest请求
        req.Method = "POST";
        req.ContentType = "application/x-www-form-urlencoded;charset=gb2312";
        req.ContentLength = bytesToPost.Length;
        using (Stream reqStream = req.GetRequestStream())
        {
            reqStream.Write(bytesToPost, 0, bytesToPost.Length);     //调用
        }
        HttpWebResponse cnblogsRespone = (HttpWebResponse)req.GetResponse();
        if (cnblogsRespone != null && cnblogsRespone.StatusCode == HttpStatusCode.OK)
        {
            StreamReader sr;
            using (sr = new StreamReader(cnblogsRespone.GetResponseStream()))
            {
                responseResult = sr.ReadToEnd();  //获取返回值
            }
            sr.Close();
        }
        cnblogsRespone.Close();
        DataResult item = JsonConvert.DeserializeObject<DataResult>(responseResult);
        if (item.success)
        {
            return 1;
        }
        else
        {
            return 0;
        }
    }

    /// <summary>
    /// 图片转Base64
    /// </summary>
    /// <param name="Imagefilename"></param>
    /// <returns></returns>
    public static string ImgToBase64String(string Imagefilename)
    {
        try
        {
            Bitmap bmp = new Bitmap(Imagefilename);
            MemoryStream ms = new MemoryStream();
            bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
            byte[] arr = new byte[ms.Length];
            ms.Position = 0;
            ms.Read(arr, 0, (int)ms.Length);
            ms.Close();
            return Convert.ToBase64String(arr);
        }
        catch (Exception ex)
        {
            return null;
        }
    }

            调用返回java.lang.IllegalArgumentException: bad base-64

1个回答

bad base-64,说明你的base64编码有错误,或者参数的格式不对。我没有你的服务器没法帮你调试,你用fiddler自己抓包看看

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!