이것은 소리가 날 수 있지만 다른 웹 사이트에 파일을 게시해야하는 MVC3 작업 (서버 측 코드)이 있습니다. 두 사이트 모두 제어 할 수 있지만 두 번째 사이트는 게시 된 파일 데이터를 수신하지 않습니다. 나는 성공적으로 원격 사이트에서 파일을 요청하는 WebRequest 클래스를 사용하기 때문에 나는이 방법을 사용하여 파일 데이터를 게시 할 수있는 생각 :하나의 MVC3 작업에서 다른 사이트로 파일 게시
private WebRequest _SetupCopyToRequest(string source, string expectedDestination)
{
var request = HttpWebRequest.Create(_Settings.CopyToServerUrl);
var info = new FileInfo(source);
request.Method = "POST";
request.ContentLength = info.Length;
request.ContentType = "multipart/form-data";
var dispositionValue = String.Format("form-data; name=\"file\"; filename=\"{0}\"", expectedDestination);
request.Headers.Set("Content-Disposition", dispositionValue);
using (var destStream = request.GetRequestStream())
{
using (var sourceStream = info.OpenRead())
{
var length = (int) info.Length;
var buffer = new byte[info.Length];
sourceStream.Read(buffer, 0, length);
destStream.Write(buffer, 0, length);
}
}
return request;
}
내 문제는 수신 사이트의 작업을 최대한 빨리 전화 요청을 수신하는 것입니다 첫 번째 사이트에는 request.GetRequestStream()
이고 두 번째 사이트에서는 Request.Files가 비어 있습니다.
[HttpPost]
public ActionResult CopyToServer()
{
if (Request.Files.Count == 0 || Request.Files[0].ContentLength == 0)
return new ContentResult();
var file = Request.Files[0];
var fileName = Path.GetFileName(file.FileName);
var directory = Path.GetDirectoryName(file.FileName);
var uniqueFileName = CeoPath.GetUniqueFileName(directory, fileName);
var path = Path.Combine(directory, uniqueFileName);
file.SaveAs(path);
return new ContentResult {Content = path};
}
그래서 첫 번째 사이트의 서버에서 내 파일 데이터가 두 번째 사이트의 서버에 게시 내가합니까 방법 : 다음 두 번째 사이트의 수신 동작에 대한 코드는?