上传视频到优酷服务器时出错,求高手指点迷津~
在优酷的上传视频API中(WINFORM),要执行一系列的操作,前面已陆续测试成功,现在在一个叫“upload_slice”的API中需要传递二进制数据,他的API具体说明如下:
upload_slice
InterfacePOST http://gX.upload.youku.com/gupload/upload_slice?< .. parameters .. >
< .. BINARY DATA .. >
Parameters
upload_token: string, MUST provide.
slice_task_id: int, MUST provide. the slice upload task ID.
offset: int64, MUST provide. the offset in the source file.
length: int, MUST provide. the data length.
crc: string, CRC32 of the data slice in hex string. default is empty string (””).
hash: string, MD5 of the data slice in hex string. default is empty string (””).
data: binary.
Note: One of CRC or HASH is recommented for error testing and slice re-uploading.
Return Value
error: object. Only returned when error occured.
code: int.
type: string.
description: string.
slice_task_id: int, MUST provide. the next slice upload task ID.
offset: int64, MUST provide. the offset of the next slice in the source file to upload.
length: int, MUST provide. the data length of the next slice to upload.
transferred: int64. the data length that already uploaded.
finished: boolen, whether or not the file is totally uploaded.
Error Codes
120010205 - Invalid upload session id
120010212 - Internal error: memory error
120010218 - CRC check error
120010219 - Resource unavailable
120010221 - Duplicated operation
120010224 - Bad request
120010225 - Hash check error
See Error Definition for full list of error definitions.
Sample (for demo only; layout for ease of reading)
POST /gupload/upload_slice?upload_token=1a2b3c4d
&slice_task_id=1328792850123
&offset=12345678
&length=12345
&crc=dfc6f27b
Host: g01.upload.youku.com
< .. BINARY DATA .. >
----
201 Created
{ "slice_task_id": 1328793281567,
"offset": 12358023,
"length": 12345,
"transferred": 12358023,
"finished": false }
现在的问题是,如果把包含“文本”和二进制数据的内容一起POST到服务器?
难道是把2部分分开再合并起来发送?如我下面的代码所示:
其中,ZdSoft.Framework.Helper.HttpRequest.DoPostRequest是我自己的类,发送POST请求的,mergerArray是合并数组数据用的,但是服务器一直返回400,我要怎么解决?求高手指点!
upload_slice
InterfacePOST http://gX.upload.youku.com/gupload/upload_slice?< .. parameters .. >
< .. BINARY DATA .. >
Parameters
upload_token: string, MUST provide.
slice_task_id: int, MUST provide. the slice upload task ID.
offset: int64, MUST provide. the offset in the source file.
length: int, MUST provide. the data length.
crc: string, CRC32 of the data slice in hex string. default is empty string (””).
hash: string, MD5 of the data slice in hex string. default is empty string (””).
data: binary.
Note: One of CRC or HASH is recommented for error testing and slice re-uploading.
Return Value
error: object. Only returned when error occured.
code: int.
type: string.
description: string.
slice_task_id: int, MUST provide. the next slice upload task ID.
offset: int64, MUST provide. the offset of the next slice in the source file to upload.
length: int, MUST provide. the data length of the next slice to upload.
transferred: int64. the data length that already uploaded.
finished: boolen, whether or not the file is totally uploaded.
Error Codes
120010205 - Invalid upload session id
120010212 - Internal error: memory error
120010218 - CRC check error
120010219 - Resource unavailable
120010221 - Duplicated operation
120010224 - Bad request
120010225 - Hash check error
See Error Definition for full list of error definitions.
Sample (for demo only; layout for ease of reading)
POST /gupload/upload_slice?upload_token=1a2b3c4d
&slice_task_id=1328792850123
&offset=12345678
&length=12345
&crc=dfc6f27b
Host: g01.upload.youku.com
< .. BINARY DATA .. >
----
201 Created
{ "slice_task_id": 1328793281567,
"offset": 12358023,
"length": 12345,
"transferred": 12358023,
"finished": false }
现在的问题是,如果把包含“文本”和二进制数据的内容一起POST到服务器?
难道是把2部分分开再合并起来发送?如我下面的代码所示:
/// <summary>
/// 合并数组
/// </summary>
/// <param name="first"></param>
/// <param name="second"></param>
/// <returns></returns>
private byte[] mergerArray(byte[] first, byte[] second)
{
byte[] result = new byte[first.Length + second.Length];
first.CopyTo(result, 0);
second.CopyTo(result, first.Length);
return result;
}
private void btn_upload_slice_Click(object sender, EventArgs e)
{
//upload_slice
byte[] data2 = File.ReadAllBytes(file_name);
Encoding encoding = Encoding.UTF8;
uint crc = my_CRC32.CalculateDigest(data2, (uint)0,length);
//MessageBox.Show(crc.ToString());
string postData = "upload_token=" + upload_token + "\r\n";
postData += ("&slice_task_id=" + slice_task_id + "\r\n");
postData += ("&offset=" + offset + "\r\n");
postData += ("&length=" + length + "\r\n");
postData += ("&crc=" + crc + "\r\n");
//postData += ("&data=" + "\r\n");
//MessageBox.Show(postData);
//postData += File.ReadAllBytes(file_name)+ "\r\n";
byte[] data = encoding.GetBytes(postData);
string content = ZdSoft.Framework.Helper.HttpRequest.DoPostRequest("http://g" +
gX + ".up.youku.com/gupload/upload_slice",
mergerArray(data, data2), 1);
//MessageBox.Show(content);
btn_upload_slice.Enabled = false;
}其中,ZdSoft.Framework.Helper.HttpRequest.DoPostRequest是我自己的类,发送POST请求的,mergerArray是合并数组数据用的,但是服务器一直返回400,我要怎么解决?求高手指点!
...全文
相关推荐
如何运用CaTICs网站开展认证考试(ppt文档).ppt
通过观看视频教程(http://v.youku.com/v_show/id_XNjUxMzUzMjky.html),教师能快速定制个性化试卷。4.
高清视频录制工具(Bandicam) v3.3.3.1209中文免费版.zip
Bandicam与Fraps、Dxtory被广大游戏视频录制爱好者合称为世界三大游戏录制神器。其中Bandicam优势明显,绝对是广大视频录制爱好者的首选!!Bandicam 一款由韩国开发的高清录制
园林绿化CAD插件最新版3.0(特色:植物配置快速标注与算量,规则云线)
**视频教程支持**:提供的视频演示链接(http://v.youku.com/v_show/id_XNjA5ODE0MTA0.html)可帮助用户更好地理解和使用该插件,通过实际操作示例,让学习变得更加直观易懂
Bandicam 录频软件
视频录播,截图之用,使用文本Bandicam与Fraps、Dxtory被广大游戏视频录制爱好者合称为世界三大游戏录制神器。其中Bandicam优势明显,绝对是广大视频录制爱好者的首选!! Bandic
淘宝助理5最新版本
淘宝助理V5.0版登陆优化增加对账户二次验证的支持。快递单打印优化宝贝简称、宝贝数量、商家编码选项。发货单打印模板优化、订单物流信息优化增加促销、运费字段;整合留言、备注界面。 订单展示列表优化增加订


OpenAPI
