我正在尝试将字节数组发布到服务器。
我的代码:
private void PostVideo()
{
byte[] data = null;
InputStream st;
st = new FileInputStream (Android.OS.Environment.ExternalStorageDirectory + "/newtest.mp4");
data = readBytes (st);
var _video = new VideoViewModel{Title = "title", User_Id = 1 , video = data};
var requestpost = HttpWebRequest.Create (string.Format (@"http://***/api/Video", ""));
requestpost.ContentType = "multipart/form-data";
requestpost.Method = "POST";
using (var writer = new StreamWriter (requestpost.GetRequestStream ())) {
writer.Write (_video);
}
using (HttpWebResponse response = requestpost.GetResponse () as HttpWebResponse) {
if (response.StatusCode != HttpStatusCode.OK)
System.Console.Out.WriteLine ("Error fetching data. Server returned status code: {0}", response.StatusCode);
else
// response
}
}
public class VideoViewModel
{
public int User_Id { get; set; }
public string Title { get; set; }
public byte[] video { get; set; }
}
public byte[] readBytes(InputStream inputStream){
ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
int bufferSize = 1024;
byte[] buffer = new byte[bufferSize];
int len = 0;
while ((len = inputStream.Read(buffer)) != -1) {
byteBuffer.Write(buffer, 0, len);
}
return byteBuffer.ToByteArray();
}
我没有收到任何错误或输出。在HttpWebResponse上出现突破点,然后没有任何反应。
我在这里做错了什么?
请帮忙, 谢谢