/// <summary>
/// 发送Post请求腾讯云
/// </summary>
public static string SendPost(byte[] image)
{
var url = @"http://recognition.image.myqcloud.com/ocr/businesscard";
try
{
ServicePointManager.Expect100Continue = false;
var request = (HttpWebRequest)WebRequest.Create(url);
//var parm = "{\"appid\":\"1251163641\",\"bucket\":\"test\",\"url_list\":[\"http://yoututest-1251966477.cossh.myqcloud.com/mingpian.jpg\"]}";
var parm = "appid=1251163641";
var parm1 = "image=mp.jpg";
var bs = Encoding.UTF8.GetBytes(parm);
var img = Encoding.UTF8.GetBytes(parm1);
request.Method = "POST";
request.Host = "recognition.image.myqcloud.com";
request.ContentType = "multipart/form-data;boundary=--------------acebdf13572468";
request.ContentLength = bs.Length + img.Length+image.Length;
request.Headers.Add("authorization", GetSign());
using (var stream = request.GetRequestStream())
{
stream.Write(bs, 0, bs.Length);
stream.Write(img, 0, img.Length);
stream.Write(image, 0, image.Length);
}
using (var wr = request.GetResponse())
{
//在这里对接收到的页面内容进行处理
var sr = new StreamReader(wr.GetResponseStream(), Encoding.UTF8);
string postContent = sr.ReadToEnd();
sr.ReadToEnd();
sr.Close();
return postContent;
}
}
catch (WebException we)
{
if (we.Status == WebExceptionStatus.ProtocolError)
{
using (var s = we.Response.GetResponseStream())
{
var reader = new StreamReader(s, Encoding.UTF8);
string postContent = reader.ReadToEnd();
return postContent;
}
}
else
{
throw we;
}
}
catch (Exception e)
{
throw e;
}
}
提交中是提示 找不到 appid 谁知道为什么啊, sdk没有C#版本的 所以只能自己写post请求 使用 json的就没问题
相似问题