Comments (2)
from httplib.
webapi code like this:
vs2017, iis10 on win10 64x, dotnet 4.6, mvc 5.2.3.0
class ValuesController : ApiController {
[HttpPost]
public async Task<Dictionary<string, string>> Post(int id = 0)
{
// if MultipartBodyProvider.cs string.Format("multipart/form-data, boundary={0}", boundary);
// The following code will not pass
if (!Request.Content.IsMimeMultipartContent())
{
throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
}
Dictionary<string, string> dic = new Dictionary<string, string>();
string root = HttpContext.Current.Server.MapPath("~/App_Data");
var provider = new MultipartFormDataStreamProvider(root);
try
{
// run to this code will be throw error "Unexpected end of MIME multipart stream. MIME multipart message is not complete"
await Request.Content.ReadAsMultipartAsync(provider);
foreach (MultipartFileData file in provider.FileData)
{
Trace.WriteLine(file.Headers.ContentDisposition.FileName);
Trace.WriteLine("Server file path: "+file.LocalFileName);
}
foreach (var key in provider.FormData.AllKeys)
{
dic.Add(key, provider.FormData[key]);
}
}
catch (Exception ex)
{
throw ex;
}
return dic;
}
}
the post code
Http.Post("http://localhost:90/api/values/1").Upload(files:
new[] {
new NamedFileStream("zzz.zip", @"F:\zzz.zip", "application/octet-stream", File.OpenRead(@"F:\zzz.zip"))
}).OnSuccess((s) =>
{
WriteLine("--success--");
WriteLine(s);
}).OnFail((s) =>
{
WriteLine("--fail--");
WriteLine(s);
}).Go();
normal form post will success
<form action="http://localhost:90/Api/Values/1" method="post" enctype="multipart/form-data">
<input name="id" value="1" />
<input id="d" type="file" src="F:\work\11.xls" name="d"/>
<input id="e" type="file" src="F:\work\22.xls" name="e"/>
<input type="submit" value="tj" />
</form>
thanks !
from httplib.
Related Issues (20)
- 怎么做到同步
- example for asynchronous operation HOT 1
- set the synchronous and asynchronous HOT 1
- Headers are not being set. HOT 5
- DELETE method must be set Content-Type HOT 2
- Why did you collect all the requests? HOT 2
- how to solve this exception? with exception callback? or surround by try ... catch ... ? HOT 22
- Invalid URI: The Uri string is too long HOT 1
- set Headers HOT 1
- \n or \r\n HOT 1
- Runtime exception HOT 2
- Add header "Range" HOT 2
- How can I access my server with https HOT 1
- How do you get the return information using post?
- Add header User-Agent.
- SettableActionProvider constructs have problems HOT 4
- Can't upload file bigger than 2G HOT 4
- The request will use IE defalut proxy,how to close it
- how to import into my project? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from httplib.