【发布时间】:2015-10-05 22:55:54
【问题描述】:
我正在尝试从我的 Android 客户端接收一个冗长的 base64 字符串,然后将其解码为我的 Web API 项目中的位图,以作为图像上传到 Azure BLOB 存储。但是,项目返回此消息并拒绝接受参数:
请求网址过长
HTTP 错误 414。请求 URL 太长。
显然 base64 字符串很长。我如何解决这个问题并接受参数?我在堆栈中查看了类似的问题,但没有一个答案清楚地说明如何在 Web API 中修复它。谢谢!
这是我方法中的代码 sn-p:
[HttpPost]
[Route("api/addnewpost")]
public IHttpActionResult AddNewMediaActivity(string base64String, string caption, string email, string type)
{
byte[] f = Convert.FromBase64String(base64String);
//more code........
}
我在 Android 上的客户端代码:
HttpClient hc = new DefaultHttpClient();
String message;
HttpPost p = new HttpPost("http://mymobileaddress.azure-mobile.net/api/addactivity?base64String=" + image + "&caption=" + caption + "&email=" + email + "&type=" + type );
JSONObject object = new JSONObject();
try {
object.put("base64String", image);
object.put("email", image);
object.put("base64String", image);
} catch (Exception ex) {
}
try {
message = object.toString();
p.setEntity(new StringEntity(message, "UTF8"));
p.setHeader("Content-type", "application/json");
p.setHeader("ACCEPT", "application/json");
p.setHeader("X-ZUMO-APPLICATION", mobileServiceAppId);
HttpResponse resp = hc.execute(p);
if (resp != null) {
if (resp.getStatusLine().getStatusCode() == 204)
{
}
}
Log.d("ER", "" + resp.getStatusLine().getStatusCode());
} catch (Exception e) {
e.printStackTrace();
}
【问题讨论】:
-
@Zaki 不走运。不工作:(
-
正常的方式是通过 body 发布数据 .... 而不是通过 url ...
-
@Selvin 请解释一下,我对这些东西有点落后,我不知道:(
-
嗯,这都是互联网上成千上万的例子......搜索 FromBody 属性
标签: asp.net web-services asp.net-web-api