Loopj - 使用 RequestParams c# .net 上传文件
Posted
技术标签:
【中文标题】Loopj - 使用 RequestParams c# .net 上传文件【英文标题】:Loopj - Uploading Files with RequestParams c# .net 【发布时间】:2016-02-04 09:07:23 【问题描述】:尝试使用 loopj 上传带有参数的文件。 我试图从 Request.Files 获取文件,从 Request.Form["create"] 获取参数 但它没有上传到服务器。
android Post 方法
try
String createTeamURL = "http://url";
RequestParams params = new RequestParams();
params.put("file", new File(pathoffile));
params.add("create", regString);
AsyncHttpClient client = new AsyncHttpClient();
client.post(createTeamURL, params, new AsyncHttpResponseHandler()
@Override
public void onStart()
// called before request is started
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] response)
// called when response HTTP status is "200 OK"
@Override
public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e)
// called when response HTTP status is "4XX" (eg. 401, 403, 404)
@Override
public void onRetry(int retryNo)
// called when request is retried
);
catch (Exception e)
Log.e("createTeamPreStep", e.getMessage());
我的 Web Api c# 方法
[HttpPost]
public async Task<string> CreateUHS()
var resultString = "";
foreach(HttpPostedFileBase s in Request.Files)
var a=s;
String sdf = Request.Form["create"];
【问题讨论】:
【参考方案1】:您需要将 put 用于字符串参数。 请在下面找到服务器和客户端方法。 还有一件事我真的很担心你的命名变量。这不好。请更改它。编码愉快。
String createTeamURL = "http://url";
RequestParams params = new RequestParams();
params.put("file", new File(pathoffile));
params.put("create", regString);
服务器(Web api)
[HttpPost]
public async Task<string> CreateUHS()
var file=Request.Files[0];
String otherArg = Request.Form["create"];
【讨论】:
以上是关于Loopj - 使用 RequestParams c# .net 上传文件的主要内容,如果未能解决你的问题,请参考以下文章
AsyncHttpResponseHandler 未定义发送参数;RequestParams,android,java,php
@JsonCreator 不适用于 Spring MVC 中的 @RequestParams
反向代理请求在loopj.AsyncHttp中的onSuccess中返回null